13 chars · 1 line
5 chars · 1 line
13 chars · 1 line
5 chars · 1 line
Regex replacement behavior
JavaScript replacement strings can reuse captured substrings with tokens such as $1 and $2. The preloaded example captures a last name and first name, then reverses their order in Replace mode. This tool is free to use. No account or payment is required.
Last updated
$1 refers to capture group 1, $2 to capture group 2, and so on. The complete matched text has separate replacement syntax, so capture numbering should be checked whenever grouping changes.
Reverse Last, First into First Last.
(\w+),\s*(\w+)
$2 $1
Lovelace, AdaAda LovelaceCommon questions
It inserts the substring captured by the first capturing group in the regex.
Yes. JavaScript also provides replacement syntax for named capture groups.
Adding or removing ordinary capturing groups can renumber later captures. Use non-capturing groups when parentheses are needed only for structure.
Debugging a specific Regex issue? Browse Regex troubleshooting.