Regex Replace Tester
Test a regex find-and-replace pattern live and preview the resulting output text, with support for $1, $2 capture group syntax.
Supports JavaScript replace syntax like $1, $2 for capture groups.
Result After Replace
How to Use the Regex Replace Tester
Enter a regular expression pattern, toggle the g (global), i (ignore case), and m (multiline) flags, type a replacement string, and paste sample text — the tool runs JavaScript's String.replace() live and shows exactly what the resulting text looks like. The replacement string supports standard capture-group syntax like $1 and $2 to reuse parts of each match.
Example
Pattern (\w+)@(\w+)\.com with global matching against "Contact us at hello@example.com or sales@example.com.", replaced with $1[at]$2[dot]com, produces "Contact us at hello[at]example[dot]com or sales[at]example[dot]com." — each captured group is reinserted into the replacement text.
Common Use Cases
- Previewing a find-and-replace regex before running it against real code or data.
- Testing capture-group substitution patterns like
$1and$2before using them in scripts. - Cleaning or reformatting sample text (like masking emails or normalizing whitespace) interactively.
FAQs
- How is this different from the Regex Tester? The Regex Tester only tests and highlights matches within your sample text — it shows you what a pattern finds, but doesn't change anything. This Regex Replace Tester goes one step further and specifically previews the find-and-replace OUTPUT text, running your pattern through JavaScript's
String.replace()with your replacement string so you can see the transformed result before using it in real code. - What happens if my pattern is invalid? The tool catches the error from JavaScript's regex engine and displays a friendly error message instead of crashing, so you can fix your pattern and keep experimenting without losing your sample text or replacement string.
- How do I reuse captured groups in the replacement? Wrap the parts of your pattern you want to reuse in parentheses, then reference them in the replacement string as
$1,$2, and so on, in the order the groups appear in the pattern — this is standard JavaScriptString.replace()syntax.
