Regex Tester

[ MATCHES ]
3
3 groups · 1 named
Matches3
Groups3
Named groups1
[ EVERY MATCH ]
line 1 · at 50917 555 1234
$1: 0917
$2: 555
$3: 1234
$<area>: 0917
line 1 · at 220918-555-9876
$1: 0918
$2: 555
$3: 9876
$<area>: 0918
line 2 · at 560922 555 0000
$1: 0922
$2: 555
$3: 0000
$<area>: 0922
[ WHAT THIS IS ]

Three of the six flags are routinely misunderstood, so they are written out on the page.

A dot does not match a newline unless s is on. People reach for m instead — but that is a different thing: it changes what ^ and $ mean. It is the commonest reason a pattern stops at the end of a line.

A group that did not participate is undefined, not empty. In (a)|(b) against b, group one never took part — and a tester printing an empty string there has told you something false. That is where most confusion about a pattern actually lives.

And catastrophic backtracking cannot be prevented here. JavaScript offers no way to interrupt a running match. The honest version: this runs in YOUR browser, so the worst case is this tab freezing.

[ QUESTIONS ]

Why does my pattern stop at the end of a line?

Because a dot does not match a newline unless the s flag is set. People reach for m instead, which is a different thing — m changes what ^ and $ mean, so they match at every line break rather than only at the ends of the whole text. If you want a dot to cross a newline, you want s.

What is the difference between having the g flag and not?

Without g a pattern reports only the first match — that is what non-global means rather than a limitation of this page. With g you get every one. It also matters for replacing: a non-global replace changes the first occurrence and leaves the rest.

Why is one of my groups shown as “did not participate”?

Because it genuinely did not. In a pattern like (a)|(b) matched against b, group 1 never took part, and its value is undefined rather than an empty string. Most testers print nothing there, which suggests it matched emptiness — a different and misleading thing. This is usually where confusion about a pattern actually lives.

What does “matches the empty string” mean?

That your pattern can match nothing at all, so it matches at every position between characters. Usually a quantifier that should be + is a *: \d* matches an empty string anywhere, while \d+ needs at least one digit. It is rarely what anybody wants and it is easy to miss, so the page says so.

Can a pattern freeze my browser?

Yes. A pattern nesting one quantifier inside another — the shape of (a+)+ — can take exponential time on input that almost matches. JavaScript offers no way to interrupt a running match, so no tool can truly prevent it. This page caps the input, caps the match list, and warns when it recognises the shape. It runs in your browser, so the worst case is this tab freezing rather than a server going down.

Does this use the same regex engine as my code?

If your code is JavaScript, yes — this uses the browser’s own RegExp. Other languages differ in real ways: lookbehind, named group syntax, possessive quantifiers and what \b means around non-ASCII letters all vary. Test against the engine you will actually run on before relying on a pattern.

Is my text sent anywhere?

No. Everything is matched in your browser and nothing is transmitted or stored.

[ THE MATHS ]
The six flags
gevery match, not only the first
iignore upper and lower case
m^ and $ at every line break
sa dot now crosses a newline
ucode points, so \p{L} works
yonly at lastIndex

m and s are the pair most often swapped. They do different jobs.

[ THE SHAPE THAT EXPLODES ]

(a+)+ — a quantifier inside a quantifier — can go exponential on input that almost matches. The page warns rather than refusing: it may be perfectly fine on the input you actually have. A hint, not a guarantee.

[ NEXT ]
52Find and ReplaceWhen you know what you want and just want it changed
54Text ExtractorThe common patterns, already written
48Text ComparisonFor differences a pattern will not find
50Line ToolsTidy the list your matches produced
[ IMPORTANT ]

Runs in your browser using its own RegExp engine, so results match JavaScript. Other languages differ on lookbehind, named groups and word boundaries. A pattern nesting quantifiers can take exponential time and no tool can interrupt it — the warning is a hint, not a guarantee. Nothing you type here is sent to our servers — the calculation runs entirely in your browser.