100% Client-Side: Your data is processed locally and never leaves your browser.

Regex Tester & Replacement Playground

Test patterns with JavaScript regular-expression semantics, inspect capture groups, and preview replacements without changing your source text.

g
Flags

36 / 100,000 characters. Matching and replacement run in a disposable Worker with a 500 ms timeout.

Global (g) replaces every match; without it, only the first match is replaced. JavaScript replacement tokens such as $1 and $& are supported.

Engine: the browser's JavaScript RegExp implementation. Pattern limit: 500 characters. Sample limit: 100,000 characters. Replacement previews are capped at 1,000,000 characters and 5,000 matches. A timed-out worker is terminated to keep the page responsive.

How to use this tool

  1. Enter a JavaScript regular-expression pattern and select the flags to use.
  2. Add sample text and an optional replacement string.
  3. Review highlighted matches, capture groups, and the replacement preview.

Technical logic and worked examples

Patterns use JavaScript RegExp syntax and the selected flags. The global flag finds successive matches; capture groups can be referenced in replacements with $1, while $& inserts the full match. Evaluation runs in a disposable worker with input limits and a timeout.

  1. Pattern \w+ with the global flag matches “cat” and “dog” in “cat dog”; replacement [$&] previews as “[cat] [dog]”.
  2. Pattern (\d{4})-(\d{2})-(\d{2}) with replacement $2/$3/$1 transforms “2025-01-31” into “01/31/2025”.

Frequently asked questions

Which regular-expression syntax does this tester use?

It uses JavaScript RegExp syntax, including supported JavaScript flags, capture groups, named groups, and replacement tokens.

What does the global flag do?

The g flag finds successive matches throughout the sample text instead of stopping after the first match.

How do I reference capture groups in a replacement?

Use $1, $2, and so on for numbered capture groups, or the JavaScript replacement syntax for named captures. $& inserts the entire match.

Why might a pattern stop running?

The tester limits input size and runs expressions in a disposable worker with a timeout. Expressions exceeding the time limit are stopped to keep the page responsive.

Examples