Skip to content

Regex replace tester

Preview a bounded regular-expression replacement locally and export its exact text output.

Replacement preview26 chars
A bounded JavaScript-style pattern, without lookarounds or backreferences.
g i m s u
Up to 20,000 characters. The preview shows at most 1,000 matches.
Use $&, $1–$99, $<name>, or $$; $` and $' are intentionally refused.
Live replacement output Ready
28 output chars
last, first and world, hello
Processed on your device

How it works & useful details

Preview a controlled replacement

Replacement output supports literal text, $$, $&, numbered captures $1–$99, and named captures $<name>. The live preview and exported text use the same bounded transform.

Source-copy tokens $` and $' are refused because repeated matches can multiply output. The regex safety rules from the regex tester apply here too.

Private, bounded text processing

Code and markup stay as inert text in this browser. These tools do not execute JavaScript, render HTML, load URLs, install packages, contact registries, or save what you paste.

Regex patterns are limited to 500 characters and test text to 20,000 characters. Formatters and package inspection accept up to 100,000 characters; exports are capped at 200,000 characters.

About this tool

Regex replace tester shows the exact result of applying a bounded regular-expression replacement to your text. Use it to preview a bulk edit before running it in your editor or a migration script.

Everything happens locally, and the output is the precise replaced text rather than an approximate preview. Flags for global, case-insensitive, and multiline matching can be toggled per test.

How to use it

  1. Enter the pattern and the replacement string.
  2. Paste the text you want to transform.
  3. Choose the flags you need, such as global or case-insensitive.
  4. Review the replaced output and export the exact result.

Worked example

Pattern (\w+)-(\w+), flag g, replacement "$2, $1", applied to "first-last and hello-world", gives:

last, first and world, hello

Each match captures two words. The replacement writes the second capture, a comma, and then the first, and the g flag applies it to every match. Two replacements are reported.

Replacement syntax

  • $1 to $99 insert numbered capture groups.
  • $<name> inserts a named group, defined with (?<name>…) in the pattern.
  • $& inserts the whole match, for example to wrap it: [$&].
  • $$ inserts a literal dollar sign.

This is the syntax used by JavaScript's String.replace and many editors, including VS Code. Other languages differ: Python uses \1 and \g<name>, and sed uses \1. Preview a bulk change here before running it across a codebase or a database export, and check the replacement count against what you expected.

Frequently asked questions

Are capture groups supported in the replacement?

Yes. Standard replacement references such as $1 work, and the preview shows the final text. Unsupported constructs are reported.

Can I see which parts matched?

The tester focuses on the replaced output. For offsets and captures, use the regex tester.

What are the limits?

Patterns are limited to 500 characters and test text to 20,000 characters.

Why are $` and $' refused?

They insert the text before and after the match. With many matches this can multiply the output size dramatically, so they are blocked to keep the preview fast and predictable.