Regex Tester
text / regex Regex Tester
Build and test regular expressions against your own text, with every match highlighted as you type. Capture groups — numbered and named — are listed per match, flags can be toggled individually, and a replacement preview shows what a substitution would produce. A cheat sheet of the syntax sits below the tool. Everything runs in your browser.
How the tool works
The pattern is compiled with the JavaScript regular expression engine, so what you see here is exactly what String.prototype.match and friends will do in a browser or in Node. Matching re-runs on every keystroke; if the pattern will not compile, the engine's own error message is shown rather than a generic failure.
Matches are highlighted in place and listed in a table with their starting position, the matched text, and the contents of every capture group. The replacement field accepts the standard substitution syntax: $1 inserts the first capture group, $<name> a named one, and $& the whole match.
The flags
Patterns here use the JavaScript flavour specified in ECMA-262, which differs from PCRE and from Python in places that matter — lookbehind support, named group syntax, and the meaning of $ under the multiline flag among them. A pattern copied from another language may compile here and match differently.
The u flag raises matching from code units to code points, which is the difference between UTS #18 level 1 support and something that mishandles any character outside the Basic Multilingual Plane — emoji included.
- g — global.Find every match rather than stopping at the first. This tool always matches globally so it can list them all.
- i — ignore case.
/cat/imatches "Cat" and "CAT". - m — multiline.Makes
^and$match at each line break rather than only at the very start and end of the input. - s — dot all.Lets
.match newlines too, which it otherwise never does. - u — unicode.Treats the pattern as Unicode code points, which is required for
\p{...}property escapes and for handling characters outside the basic plane correctly. - y — sticky.Anchors each attempt at the current position instead of searching forward.
Common uses
- Validating a field.Check a pattern against a spread of real inputs — including the ones you expect to fail — before wiring it into a form.
- Extracting data from a log.Capture groups pull timestamps, status codes, or identifiers out of unstructured lines.
- Writing a search and replace.Preview the result here before running it across a codebase in your editor.
- Understanding someone else's pattern.Paste an inherited expression, run it against sample text, and see what it actually does rather than what the comment claims.
- Building a routing or redirect rule.Confirm the pattern matches the URLs you mean and nothing more.
Things that trip people up
- Greedy quantifiers overshoot.
<.+>against<a><b>matches the whole string, not just the first tag, because+takes as much as it can. The lazy form<.+?>stops at the first>. - A dot is not a full stop.Unescaped,
.matches almost anything. To match a literal period, write\.. - Escaping doubles up in string literals.A pattern written as
\dhere becomes"\\d"inside a quoted string in most languages. - Anchors are not free.Without
^and$, a pattern that validates a value will happily match it inside a longer string — which is how validators end up accepting rubbish with a valid fragment buried in it. - Regular expressions cannot parse nested structures.HTML, JSON, and source code have arbitrary nesting, which is beyond what a regular expression can describe. Use a parser.
Frequently asked questions
Which flavour of regular expression is this?
Why is there a limit on the input size?
(a+)+$ against a long run of "a" characters — and can take effectively forever on input of any size. JavaScript cannot interrupt a running match, so a pattern like that would freeze the tab. Testing is capped at 100,000 characters and 10,000 matches to bound the damage.Can I use this to validate email addresses?
What does a zero-length match mean?
a* can succeed while consuming nothing, matching the empty string at each position. Those positions are counted here but have no highlighted text, which is why the match count can exceed what you see marked.