✏️Regex Replace Preview

Compare the text before and after

References you can use in the replacement

$1 to $9 are numbered capture groups, $<name> is a named group, $& is the whole match, $` is the text before the match, $' is the text after it, and $$ is a literal dollar sign. $<name> only works when the pattern has a (?<name> ...) group.

Limits that keep the page responsive

A regular expression can explode in the number of attempts it makes on certain inputs. Feed a long run of a characters to a nested quantifier such as (a+)+$ and a browser can spend minutes looking frozen. This is called catastrophic backtracking. A JavaScript regex cannot be interrupted once it starts, so this tool caps the pattern at 300 characters and the input at 20,000.

On top of that, if nested quantifiers are spotted or the input passes 2,000 characters, the live preview pauses and the replacement runs only when you press Run. The nested-quantifier check is a heuristic: it neither catches every dangerous pattern nor proves that a flagged one is slow. The measured time is shown so you can judge for yourself.

You Might Also Need

See before and after side by side

Enter the pattern, the flags, the replacement and the input text, and the result appears next to the original. Matches and actual replacements are counted separately, so a missing g flag that changed only the first occurrence is obvious at a glance, and the change in length is reported too. The replacement accepts numbered groups such as $1 and named groups in the $ form.

Caps that stop the page from freezing

A regular expression can explode in the number of attempts it makes on certain inputs. Give a nested quantifier like (a+)+$ a long run of a characters and it can take long enough to look frozen, a behavior known as catastrophic backtracking. A JavaScript regex cannot be interrupted once it starts, so the pattern is capped at 300 characters and the input at 20,000, with the measured time shown alongside. Checked October 2026.

A heuristic warning, and what it cannot promise

When nested quantifiers are spotted or the input passes 2,000 characters, the live preview pauses and the replacement runs only on the Run button. That detection is a heuristic: it does not catch every dangerous pattern, and a flagged pattern is not necessarily slow. The tool does not list match positions or the value of each capture group.

Frequently Asked Questions

Why did only the first occurrence change?

Without the g flag, JavaScript replace changes only the first match. Put g in the flags box to change them all; the separate counts for matches and replacements make the difference visible immediately.

Why does the live preview stop?

It pauses when nested quantifiers are spotted or the input passes 2,000 characters. A JavaScript regex cannot be interrupted once it starts, so combinations that might run long are left for the Run button.

What does this tool not do?

It does not list match positions or the value of each capture group. Match inspection belongs to a regex tester, and explaining a pattern to a regex explainer.