RegexCalc Regex Engine

Regex Replace Tester

Test a regex replacement live in your browser's own JavaScript engine, with numbered and named groups, the whole match, the text before and after it, and literal $ escaping, then share the result as a link.

Regex Replace 100% CLIENT-SIDE

Live preview from your browser's own String.prototype.replace, so $&, $`, $', $1–$99, $<name> and $$ behave exactly as they will in your code. The g flag is added automatically.

Pattern & Replacement
Subject Text
Replaced Output

What each replacement token does

The outputs below were produced by this page's replace function when the site was built, and checked against JavaScript's own String.prototype.replace on the same input. Several are cases where a guess about the syntax goes wrong: a group that does not exist, two digits after a $, and an empty pattern.

ReplacementPattern and inputOutputWhy
$3/$2/$1/(\d{4})-(\d{2})-(\d{2})/g on 2026-11-0707/11/2026Reorder a date by referring to each group by number.
$<m>/$<y>/(?<y>\d{4})-(?<m>\d{2})/g on 2026-1111/2026Named groups survive edits to the pattern better than numbers do.
[$&]/cat/g on cat dog cat[cat] dog [cat]$& stands for whatever matched, so you can wrap matches without capturing them.
$$$&/\d+/g on price: 5price: $5$$ writes one $, so $$$& is a dollar sign followed by the match.
<$`|$'>/dog/g on a dog ba <a | b> b$` inserts everything before the match and $' everything after it.
$2/(a)/g on a$2A reference to a group that does not exist is left as literal text, so a typo shows up in the output instead of vanishing.
$10/(\w)(\w)/g on aba0With only two groups, $10 falls back to group 1 followed by a literal 0. Name the group if you need a digit right after it.
[$2]/(a)(b)?/g on a[]A group that exists but did not take part in the match becomes an empty string.
-//g on abc-a-b-c-An empty pattern matches at every position, including both ends, so a 3-character string gets 4 replacements.

More from RegexCalc

Guides

All tools →All 13 guides →

Developer Sponsor / Partner
Copied to clipboard!