#497 · Developer Tool

Regex Replace Preview

Preview JavaScript regular-expression replacement without modifying the source box. Supply a pattern, replacement string, and flags; the result reports how many matches will be replaced and shows the complete transformed text. Numbered captures, named captures, dollar escapes, and function-free JavaScript replacement syntax behave as they do in String.replace.

Developer Input

Regex Replace Preview
Ad space

How to use this developer tool

  1. Paste the source text.
  2. Enter a pattern without slash delimiters.
  3. Enter the replacement string and flags.
  4. Preview the output and verify the replacement count before copying it.

What this developer tool does

The output is the exact text produced by JavaScript String.replace using the supplied pattern and replacement string.

Compile the RegExp, count matches with a separate safe iterator, then apply String.replace once to the original text.

Replacement tokens such as $&, $1, $, and $$ have JavaScript meanings.

Example

Pattern: (\w+), (\w+)
Replacement: $2 $1
Input: Lovelace, Ada
Output: Ada Lovelace

Use cases

  • Test migration replacements.
  • Reformat dates and identifiers.
  • Verify capture references before editor-wide replace.

Tips for reliable output

  • Use $$ for a literal dollar sign.
  • Add g to replace every match.
  • Check named group spelling.
  • Test multiline boundaries with m when needed.

Processing details

Match counting uses a cloned global expression and advances after empty matches. Replacement itself uses the exact requested flags, so omitting g changes only the first occurrence.

No replacement callback code is executed. The tool supports replacement-string tokens only.

Frequently asked questions

Which regular expression syntax is supported?

Patterns use the JavaScript regular expression engine available in your browser.

What happens when the pattern is invalid?

The tool reports the JavaScript syntax error and does not process the input text.

Can a regular expression freeze the page?

Pathological patterns can cause catastrophic backtracking. Test untrusted patterns on small input first.

Are matches evaluated by Unicode code point?

Only when the Unicode-related flag and pattern semantics call for it; otherwise JavaScript uses UTF-16 code units.

Does the tool send pattern or text to a server?

No. Matching and replacement run in the current browser tab.

Output fields

FieldMeaning
SummaryHigh-level processing result
StatisticsCounts and validation details
ExportCopy-ready text plus structured data when available

Code Formatting & Regex tools

Browse more tools for code formatting & regex.

Open category hub