Skip to content

Regex Tester

Tests a regular expression against sample text with live match highlighting and capture group listing.

Runs a regular expression against sample text and shows every match with its offsets, its capture groups and the replacement it would produce. It is the browser’s own engine, so what happens here is what will happen in your JavaScript.

🔒 Runs entirely in your browserregextestpattern
View

Pattern

//g

can match anywhere in the string, 2 capture groups.

Test against

Every match is listed. Without the `g` flag, `String.replace` only uses the first.

0 matches

Time

0.0 ms

ask@example.com, 문의@example.co.kr and no-reply+tag@mail.example.org

Replace

`$1`, `$<name>`, `$&`, `` $` ``, `$'` and `$$` all expand, exactly as `String.replace` expands them.

How to use it

  1. Write the pattern and set the flags

    The flag buttons are the six that matter: global, ignore case, multiline, dotAll, unicode and sticky. The literal at the top is what you would paste into code.

  2. Paste text you actually have

    Matches are highlighted in place, alternating colour so adjacent ones are distinguishable, and listed in a table with each group’s value — including the groups that did not participate.

  3. Try the replacement

    `$1`, `$<name>`, `$&`, `` $` ``, `$'` and `$$` all expand exactly as `String.replace` expands them, so the preview is the real output.

Common questions

Why does the page warn about a missing `g` flag?

Because the list shows every match, but without `g` your code will not. `String.replace` changes only the first, and `matchAll` throws outright. It is the difference between what you see here and what your program does.

Is this the same engine as Python or PCRE?

No — it is JavaScript’s. Lookbehind, named groups and `\p{…}` are supported here, but atomic groups, possessive quantifiers, recursion and inline flag groups are not, and character-class behaviour differs in places. A pattern that works here can still fail elsewhere.

My pattern hangs the page.

It should not — matching runs in a worker precisely because a catastrophically backtracking pattern cannot be interrupted any other way. If it takes too long the run is terminated and reported, which is also a useful signal: a pattern that does that here will do it on your server.

Why does `.` not match my newline?

Because that is what `s` (dotAll) is for. Without it `.` matches anything except a line terminator — and `m` (multiline) is a different thing again: it changes what `^` and `$` mean, not what `.` matches.

Feed it from

Next

These accept what this tool produces, so the result can go straight in.