Regex Replace

Replace every match of a regular expression, using capture groups in the replacement to reformat text.

Text
Result
Runs locally in your browser

About the Regex Replace

The power of regex replace is in the capture groups: match a date as three groups and write them back in a different order, wrap every number in quotes, or strip a prefix from every line. This tool applies a JavaScript regex globally to your text and substitutes the replacement, where $1, $2 refer to numbered groups and $<name> to named ones. The status counts how many substitutions were made.

The replacement string has a small syntax of its own. $& inserts the whole match, $$ inserts a literal dollar sign, and a digit after a group reference is read greedily: $12 means group 12 when the pattern has that many groups, and group 1 followed by the character 2 when it does not. Where the character after a group must be a digit, switch to a named group such as $<year> so the boundary is unambiguous.

A realistic job: an export writes dates as 2026-09-05 but the system you are importing into wants 05/09/2026, so the pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$1 rewrites the whole column in one pass. Flags behave as in the tester (i, m, s, u) and an invalid pattern is reported instead of quietly matching nothing. For plain text swaps with no pattern at all, Find and Replace is quicker, and the Regex Tester shows what a pattern selects before you commit to a substitution.

How to use

  1. Paste the text.
  2. Enter the pattern and the replacement, using $1 for groups.
  3. Copy the result; the status shows the count.

Common questions

How do I reference a group in the replacement?
Use $1, $2 for numbered groups, or $ for a named group.
Does it replace all matches?
Yes, the global flag is always applied.
How do I insert a literal dollar sign?
Write $$ in the replacement.