Regex Tester

Files & data

Test a pattern, see every match, groups and a replace preview.

Matches
3
3 groups · 1 named
Matches
3
Groups
3
Named groups
1
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

How to use

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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

  • Matches: how many times the pattern matched. Groups and Named groups count the brackets in your pattern that catch text.
  • Every match: each match with its line and its position in the text, then what each group caught as $1, $2 and so on. did not participate means that group took no part in this match, which is not the same as catching nothing.
  • After replacing: the whole text with your replacement applied. It shows only when Replace with — optional has something in it.

If it goes wrong

  • Only one match shows: the g flag is off. Turn it on to see every match.
  • A match stops at the end of a line: a dot does not cross a line break unless s is on. m is a different thing.
  • The page freezes, or a warning mentions (a+)+: the pattern has one repeat inside another, which can take a very long time on text that almost matches. Rewrite that part, or close the tab if it is stuck.

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.

Keep going

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.