Find and Replace Text

Search text with a JavaScript regular expression and replace every match in one pass. Keep the original text beside a separate result, including when the replacement removes all matching content.

Runs locally in your browser

Apply a replacement

The search field is a JavaScript regex pattern. A dot therefore has a special meaning: use \. to find an actual period. The operation runs in a browser worker without sending the entered text in a replacement request.

  1. Enter the source, then a pattern without enclosing slashes or flags. For a.a, searching for \. and replacing with - produces a-a.
  2. Set the replacement and choose Replace all. In red blue, the pattern (red) (blue) with $2/$1 produces blue/red. Leave the replacement blank to delete matches.
  3. Copy the separate result. Editing any of the three fields cancels pending work and clears the old result. Clear empties all three fields and the output.

Pattern and replacement semantics

Global, case-sensitive matching

The tool uses the g flag only. It replaces non-overlapping matches, distinguishes uppercase from lowercase, and does not enable multiline, dotAll or Unicode mode. Regex syntax support follows your browser. A missing match returns the source unchanged.

An empty pattern is valid: ab with replacement - becomes -a-b-. These zero-width positions follow UTF-16 units, which can split an emoji. The tool does not normalize Unicode or interpret the result as HTML.

Replacement tokens and processing limits

Replacement strings retain native JavaScript tokens: $1 for a captured group, $& for the full match, $$ for a dollar sign, $` for preceding text and $' for following text. Named groups can be referenced with $<name>. A typed \n in the replacement remains those two characters; it is not decoded into a line break.

Text is limited to 1,000,000 UTF-16 units, with 10,000 each for pattern and replacement. Results over 2,000,000 units are rejected after computation. A worker is stopped after a 2-second deadline, including startup; simplify the pattern or shorten the text after a timeout. No partial result is published.

Questions about replacing text

Does Replace all overwrite my source?

No. The source remains available so you can adjust the pattern and retry. To replace within an earlier result, copy it into the source yourself. An empty result is valid and can still be copied.

Why does my pattern fail?

Invalid syntax produces an error instead of an old result. Enter the pattern alone, for example \d+, not /\d+/g. If Web Workers cannot load, replacement is unavailable. Clipboard access may also depend on browser permissions; a failed copy leaves the displayed result available.

Recent tools: