Skip to content

Regex Replace Tester

Test a regular expression replacement with capture groups and see the result live.

Runs in your browserNo account neededFree
Loading tool…

Processing: This tool runs entirely in your browser. Your input and any file you open stay on your device — nothing is uploaded to a server.

How to use the regex replace tester

  1. Write your pattern and turn on the flags you need.
  2. Write the replacement, using $1 for the first group.
  3. Check the result, then copy the pattern into your code.

About this tool

Write the pattern, write the replacement, see the output change as you type. That loop is much faster than editing code and re-running it, and it is where most replacement bugs are found.

In the replacement, <code>$1</code> and <code>$2</code> insert capture groups, <code>$&</code> the whole match, and <code>$&lt;name&gt;</code> a named group. The most common mistake is forgetting the <code>g</code> flag: without it only the first match is replaced, and the result looks almost right, which is the worst kind of wrong.

A literal dollar sign in a replacement has to be written <code>$$</code>. That catches people out when replacing with currency.

Patterns run in a background worker and are stopped after two seconds. That matters more than it sounds: a pattern that backtracks catastrophically would otherwise freeze the tab completely, leaving you unable even to edit the pattern that caused it. Here it reports a timeout and the page keeps working.

Common uses

  • Reformatting dates or phone numbers in bulk.
  • Rewriting text with capture groups before pasting into an editor.
  • Checking a replacement is right before running it across a codebase.

Frequently asked questions

Why was only the first match replaced?
The g flag is off. Without it, replace stops after the first match — the most common mistake in regex replacement.
How do I insert a captured group?
$1 for the first group, $2 for the second, $& for the whole match, and $<name> for a named group.
How do I put a literal dollar sign in the replacement?
Write it as $$. A single $ followed by a digit is read as a group reference.

Related tools