How to Test a Regular Expression Live, With Groups and Replace

By Alok Singh · Published

Most developers write a regex only now and then, which is exactly the frequency at which you forget whether lookbehind is supported or why your pattern only matches once. Regex tester highlights matches as you type, lists every capture group, and previews replacements, so you can see the result before it goes into code.

Steps

  1. Type the pattern and flags, or pick an example.
  2. Paste test text.
  3. Read the highlighted matches and the table of groups, and try a replacement using $1 or $<name>.

The flavour: JavaScript

It uses your browser's JavaScript regex engine, the same as in Node.js. Most syntax is shared with PCRE, Python and Java, but there are differences in things like flag names and lookbehind support. If the pattern is destined for Python or Go, test there too before shipping.

Flags, briefly

The single most common "bug" I see is a missing g.

Replacements

In the replace box:

Example: to turn 2026-10-27 into 27/10/2026, use pattern (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) with flag g, and replacement $<d>/$<m>/$<y>. Named groups make it readable six months later.

Catastrophic backtracking

Some patterns, especially nested repeats like (a+)+ or (\w+\s?)*, can take exponential time on certain inputs. In production, that's a real outage risk (a famous one took down a large CDN for half an hour). The tester runs patterns in a separate worker with a time limit and stops runaway patterns instead of freezing your tab. If it stops yours, simplify the repeats: make them possessive in spirit by removing ambiguity, for example \w+(\s\w+)* instead of (\w+\s?)*.

Practical tips

A testing habit worth building

Keep two lists of sample text when writing a pattern: strings that must match and strings that must not. Paste both into the tester together. It's easy to write a pattern that matches all the good cases; it's the near misses, such as an extra digit, a missing hyphen or a trailing space, that reveal whether it's actually right. Once it behaves, copy both lists into a unit test so the pattern stays correct when someone edits it later.

Privacy

According to the page, your pattern and text are tested inside the page and stay on your device, so it's fine to paste log lines with internal hostnames. Google ads appear on the page, like the rest of the site.

FAQ

Which regex flavour is it? JavaScript's, as in browsers and Node.js.

Why does it only find the first match? Add the g flag.

How do I use a group in the replacement? $1 for numbered, $<name> for named groups.

Why did it stop my pattern? It hit the time limit, likely due to nested repeats. Simplify them.

Got a pattern to check? Paste it into Regex tester.

— Alok Kumar Singh


← All guides