BizTechLab

IDEASINNOVATIONIMPACT

Regex

Regex Replace

Write a pattern and a replacement — using $1, $<name>, and other backreferences — to transform text. Runs entirely in your browser; nothing you type is ever sent anywhere.

//g
Replace with
Test String
Result
Enter a pattern and replacement above to see the result here.

Quick Learn

Find-and-replace with a regex works like ordinary find-and-replace, except the "find" side is a pattern instead of literal text, and the "replace" side can reference pieces the pattern captured. $1 inserts whatever the first group matched, $<name> inserts a named group by name, and $& inserts the entire match — so a single replacement can rearrange, reformat, or partially rewrite text based on what it actually found, not just swap one fixed string for another.

This tool runs JavaScript's own String.replace() under the hood, so the replacement syntax here is exactly what you'd use in real code: $1, $2, $<name>, $&, and $$ for a literal dollar sign. Turn on the g flag to replace every match instead of just the first — the same distinction that matters for the Regex Tester tool. Everything runs locally in your browser.

Best Practices

  • Forgetting the g (global) flag is the most common reason a replace "doesn't work" — without it, only the first match in the whole string gets replaced.
  • Named groups make a replacement self-documenting: $<year>/$<month> reads far better months later than $1/$2, especially once a pattern has three or more groups.
  • $$ inserts a literal dollar sign — necessary if your replacement text should actually contain a $ character, since a bare $ followed by certain characters is otherwise interpreted as a backreference.
  • Check the highlighted "Original" preview before trusting the result on real data — it shows exactly which spans will be replaced, which catches an overly broad pattern before it rewrites more than intended.

More Regex Tools

See all Regex tools

Frequently Asked Questions

No. The replacement runs entirely in your browser using JavaScript's native String.replace() — nothing you type is sent to a server or stored anywhere.

Want the engineering deep-dives behind tools like this one?