Regex Replacer
Find and replace text using regular expressions
Enter the regex, replacement template, and source text first to see replaced output immediately; scenario examples are available in Advanced mode.
The full guide also includes pitfalls, worked examples, snippets, FAQs, and related tools for checking results or troubleshooting.
About this tool
Replace pasted text with the browser’s JavaScript RegExp and replacement-string rules. Configure a pattern without slash delimiters, flags and replacement, then inspect the output and actual match count. This page does not edit files or impose an execution timeout on complex expressions.
Production Snippets
Capture groups do not multiply replacement count
text
Input: ab ab
Pattern: (a)(b)
Flags: (empty)
Replacement: $2$1
Output: ba ab
Count: 1
With g: ba ba, count 2Frequently Asked Questions
Why is only one occurrence replaced?
Without g, replace changes only the first matching occurrence. Capturing groups do not increase the displayed count. With g, each match is counted, including zero-width matches advanced by the JavaScript engine.
How do I reuse captured text or insert a dollar sign?
Use $1 and $2 for numbered captures, $<name> for a named capture, $& for the whole match and $$ for a literal dollar. A typed \n is two characters here; it is not automatically decoded as a newline.
Which flags and regex flavor apply?
This is the current browser’s JavaScript engine, not PCRE. g, i, m, s, u and y are common flags; newer flags depend on the browser. Invalid or duplicate flags produce an error.
Can a pattern freeze the page?
Yes. Real-time replacement runs on the browser thread, and catastrophic backtracking can take a long time. Start with a small sample and simplify ambiguous nested quantifiers before processing large text.
Keep browsing