Skip to main content
Yoryantra
← Back to Tools

Regex Replace Tester

Preview JavaScript regex replacements with capture groups, replacement tokens, match positions, and changed-line output.

Paste the text you want to search and replace. Everything runs locally in your browser.

Enter JavaScript flags other than g. The “Replace all matches” option controls global replacement. Runtime-supported flags such as d, i, m, s, u, v, and y are accepted.

In JavaScript mode, use $1, $2, $&, $`, $', or $<name> for named groups.

Options

Tests JavaScript-style regex replacement behavior, including capture groups, named groups, replacement tokens, match positions, and changed lines.

Output

Regex replacement output will appear here.
Matching and replacement run in this browser session. The page does not send your input text or pattern to an API.

Test the Replacement Semantics, Not Just the Match

A pattern can match exactly what you expect and still produce the wrong edit because JavaScript replacement strings have their own syntax. Numbered captures, named captures, the complete match, and the text before or after a match can all be inserted by special dollar tokens.

Literal mode avoids those substitutions and inserts the replacement text as written. That distinction matters when the replacement itself contains dollar signs.

JavaScript Replacement Tokens

TokenMeaning
$$A literal dollar sign
$&The complete match
$1 … $99Numbered capturing groups when they exist
$<name>A named capturing group
$` / $'Text before / after the current match

These are the replacement-string rules used by JavaScript String.prototype.replace(). The MDN replacement referencegives compact examples, while the ECMAScript specification defines the normative behavior.

Flags and Replace-All Behavior

The “Replace all matches” option owns the g flag so the UI cannot silently disagree with the requested replacement scope. Other flags are passed to the browser’s RegExp engine and rejected if that runtime does not support them or if they conflict.

Match positions are JavaScript string indexes, which are UTF-16 code-unit offsets rather than Unicode code-point counts. With Unicode-aware matching, zero-length matches are advanced by a full Unicode code point to avoid splitting surrogate pairs.

Performance and Safety Boundaries

Regular expressions execute in the browser’s JavaScript engine. Certain patterns can take a very long time because of backtracking, even when the input is not huge. A preview cannot prove that a pattern is safe for arbitrary production data. Test representative input and keep backups before bulk replacement.

The table intentionally caps rendered rows while copied output can still contain the full replacement result. Very large input is flagged because rendering and regex execution can become expensive.