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.
| Replacement | Pattern and input | Output | Why |
|---|---|---|---|
$3/$2/$1 | /(\d{4})-(\d{2})-(\d{2})/g on 2026-11-07 | 07/11/2026 | Reorder a date by referring to each group by number. |
$<m>/$<y> | /(?<y>\d{4})-(?<m>\d{2})/g on 2026-11 | 11/2026 | Named 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: 5 | price: $5 | $$ writes one $, so $$$& is a dollar sign followed by the match. |
<$`|$'> | /dog/g on a dog b | a <a | b> b | $` inserts everything before the match and $' everything after it. |
$2 | /(a)/g on a | $2 | A 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 ab | a0 | With 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
Regex Tester
Type a regular expression and some text to see every match highlighted and each capture group extracted as…
Regex Explainer
Paste a regular expression to get each token explained in plain English, plus warnings measured in your…
Email Regex Pattern & Tester
A practical email pattern, pre-loaded in the tester so you can try your own addresses.
Phone Number Regex (E.164 & US Formats)
A phone number pattern covering compact E.164 numbers and the common US formats, pre-loaded in the tester.
IPv4 Address & CIDR Regex Pattern
An IPv4 pattern that limits each octet to 0-255 and allows an optional CIDR suffix, pre-loaded in the tester.
URL Regex Pattern (http & https)
A URL pattern for http and https links, pre-loaded in the tester.
UUID v4 Regex Pattern & Validator
A UUID version 4 pattern, pre-loaded in the tester.
Guides
Developer Sponsor / Partner