About the Regex Tester
This regex tester runs your pattern against sample text using the JavaScript engine already in your browser, then lists every match in a table with its index in the string and the value of each capture group. A summary reports the number of matches, the flags in force and how many capture groups the pattern declares, which is a quick way to confirm you have as many groups as you think. You can cap how many matches are displayed so a broad pattern against a long document stays manageable. An invalid pattern reports the engine's own error message, and zero-length matches are handled without freezing the page.
How to use the Regex Tester
- 1
Enter your regular expression in the Pattern field, without the surrounding slashes.
- 2
Set the Flags field: g for global, i for case-insensitive, m for multiline, s for dotall, u for unicode, y for sticky.
- 3
Paste the text you want to search into the 'Test text' box.
- 4
Adjust 'Max matches to show' if a broad pattern returns more rows than you need.
- 5
Read the Matches table for each match, its index and its capture groups, or the warning note if nothing matched.
What people use it for
Writing a validation pattern
Test an email, postcode or phone pattern against a list of both valid and deliberately invalid samples before it ever reaches your form.
Building a log-parsing expression
Paste a handful of real log lines and iterate on the capture groups until the timestamp, level and message each land in a group of their own.
Checking a find-and-replace before running it
The index column shows precisely which spans a bulk replace would touch, which is reassuring before you run it across a whole codebase.
Learning an unfamiliar pattern
Paste a regex inherited from a config file or an old answer online and watch what it actually captures rather than trusting the description alongside it.
Greedy, lazy and the cost of backtracking
By default the quantifiers star, plus, question mark and the braced form are greedy: they consume as much of the string as they can, then give characters back one at a time until the rest of the pattern matches. That is why a pattern of angle bracket, dot, plus, angle bracket applied to a bold tag pair matches the entire string rather than just the opening tag — the dot-plus swallows everything to the end, then backtracks only far enough to find a final closing bracket. Appending a question mark makes a quantifier lazy, so it takes the shortest run that works and matches the opening tag alone. A more precise alternative is usually a negated character class matching anything that is not a closing bracket, which cannot cross that character at all and so needs no backtracking. The distinction matters for performance as well as correctness. Nested quantifiers over overlapping character sets can force the engine down an exponential number of paths on an input that ultimately fails to match, a failure mode called catastrophic backtracking that has taken down production services. JavaScript has no possessive quantifiers or atomic groups, so avoiding the shape is the only defence.
Flags, groups and what the ECMAScript engine supports
The flags are single letters with distinct jobs. The g flag finds every match rather than stopping at the first, and it makes a regex object stateful through its lastIndex property. The i flag is case-insensitive. The m flag changes the caret and dollar anchors from string boundaries to line boundaries, which is the flag people usually want when a multi-line pattern mysteriously fails. The s flag, dotall, lets a dot match newline characters, which it otherwise never does. The u flag enables full unicode mode, making code point escapes and unicode property escapes work and treating surrogate pairs as single characters. The y flag, sticky, anchors each attempt at lastIndex exactly. Because this runs on the browser's own engine you get modern ECMAScript features: named capture groups, lookahead in both positive and negative forms, and lookbehind, which JavaScript supports at unrestricted width unlike several other flavours. What it lacks is recursion, conditionals and the extended whitespace flag familiar from PCRE, so patterns copied from Perl or PHP may need adapting.
Tips
- Escape a literal full stop as backslash dot — an unescaped dot matches any character and will match far more than you intended.
- The tester always adds the g flag internally so it can list every match; your own code using exec or match will behave differently without it.
- Anchor validation patterns at both ends so a partial match inside a longer string is not mistaken for a valid value.