Regex Replacer Online – Find & Replace Text

Local only

Preview JavaScript regular-expression replacements with capture groups and configurable flags before changing source text.

12 chars · 1 line

5 chars · 1 line

Pattern matched the inputFlags: g

Regex replacement guide

How to replace text with a JavaScript regular expression

Enter a pattern, flags, and replacement string above, paste the source text, then choose Replace to preview the exact JavaScript String.replace result. Capture references and global replacement follow native browser semantics. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • JavaScript String.replace semantics
  • Capture-group replacements
  • Global or first-match replacement
  • Configurable regex flags
  • Non-destructive output preview
  • Browser-local processing

Steps

  1. Enter a JavaScript regular expression pattern and choose the flags needed by the replacement.
  2. Enter a replacement string using literals or JavaScript tokens such as $1, $2, $&, or named groups.
  3. Paste the source text and choose Replace to preview the transformed result.
  4. Confirm whether the g flag should replace every occurrence or only the first match.

Use native JavaScript replacement tokens

Replacement strings follow JavaScript String.replace rules. Numbered captures can be referenced with $1 and $2, the complete match with $&, and named captures with the platform's named-group replacement syntax.

Control first-match and global replacement with flags

A regular expression without g replaces only the first matching occurrence. Add g when the transformation must apply to every match in the source text, and combine it with flags such as i or m when the matching rules require them.

Preview destructive text changes locally

Replacement happens only in the output preview. The original input remains editable in the browser, so you can test cleanup patterns against logs, code, configuration, or copied text without sending the source to a remote service.

Regex replacement example

Two capture groups reverse a first and last name with native JavaScript replacement tokens.

Pattern, replacement, and source

/(Ada) (Lovelace)/
$2, $1
Ada Lovelace

Replaced text

Lovelace, Ada

Common questions

Frequently asked questions

How do I replace every regex match?

Add the g flag. Without g, JavaScript regular-expression replacement changes only the first matching occurrence.

Can I reuse capture groups in the replacement?

Yes. JavaScript replacement strings support numbered captures such as $1 and $2 as well as other native replacement tokens.

Does Replace modify my input text?

No. The tool produces a separate output preview while the original source remains in the input editor.

Debugging a specific Regex issue? Browse Regex troubleshooting.