Regex
Regex Tester
Test regular expressions against your own text, live.
About regular expressions
A regular expression (regex) is a pattern that describes a set of strings — used to search, validate, or extract text. This tester runs JavaScript's native regex engine entirely in your browser, so you can experiment with a pattern against real text and see exactly what it matches.
Quantifiers come in two flavors that are easy to mix up: greedy ones (+, *, {2,5}) consume as much as they can before backtracking to let the rest of the pattern match, while their lazy counterparts (+?, *?, {2,5}?) consume as little as possible instead. Given <a><b> against <.+>, a greedy match grabs the whole string, while <.+?> stops at the first >. Groups have a similar fork: (...) captures the matched text for later reference, while (?:...) groups the same way without capturing — useful when you need grouping's precedence but not its output.
Where you'll run into it
- Validating input formats like email addresses, phone numbers, or postal codes
- Extracting structured values out of log lines or unstructured text
- Writing a find-and-replace pattern for a refactor across many files
- Debugging why a pattern matches more, or less, than you expected
Frequently asked
Why does my pattern only match once?
Without the g (global) flag, JavaScript's regex methods stop after the first match — that's the actual behavior your code would see too, not a limitation of this tool. Turn on g to find every match.
Is anything I type here sent to a server?
No. Matching runs entirely in your browser using JavaScript's built-in regex engine — nothing is transmitted anywhere, which also avoids exposing a server to a deliberately slow, "catastrophic backtracking" pattern.
Why does the page sometimes freeze on a pattern?
Certain patterns, like nested quantifiers such as (a+)+, can cause catastrophic backtracking, where matching time grows exponentially with input length. If a pattern hangs, it's the pattern itself, not this tool — try a shorter test string or rewrite the pattern to avoid nested repetition.
What's the difference between greedy and lazy quantifiers?
A greedy quantifier (+, *, {2,5}) matches as much text as possible up front, only backtracking if that causes the rest of the pattern to fail. Its lazy counterpart, written with a trailing ? (+?, *?), matches as little as possible instead, expanding only when it must. Against <a><b>, the greedy pattern <.+> matches the entire string, while the lazy <.+?> stops at the first >. Reach for lazy quantifiers whenever "the shortest possible match" is what you actually want.