Test a pattern, see every match, groups and a replace preview.
What it's for
Try out a regular expression — a search pattern used in code and in some spreadsheets — on sample text, and see exactly what it matches before you rely on it.
Before you start
Have the pattern you want to test, and some sample text it should match and some it should not. It runs in your browser, with the same pattern rules as JavaScript.
Type the pattern
Type it in Pattern without the slashes around it: \d+, not /\d+/. The example finds Philippine mobile numbers; replace it with yours.
Turn the flags on or off
The letter buttons under it are flags; rest the pointer on one to see what it does. g finds every match instead of only the first, i ignores capitals, m makes ^ and $ work on each line, and s lets a dot cross a line break.
Paste the text to test
Paste your sample into Test against. To preview a replacement, type it in Replace with — optional; $1 puts back what the first group caught.
Test and read the matches
Press Test to bring the answer into view; it also updates as you type. Then read the Every match list below it.
Reading the result
If it goes wrong
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.
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.
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.
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.
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.
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.
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.
No. Everything is matched in your browser and nothing is transmitted or stored.
m and s are the pair most often swapped. They do different jobs.
(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.
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.