12 chars · 1 line
5 chars · 1 line
12 chars · 1 line
5 chars · 1 line
Regex replacement guide
Enter a pattern, flags, and replacement string above, paste the source text, then choose Replace to preview the exact JavaScript String.replace result. Capture references and global replacement follow native browser semantics. This tool is free to use. No account or payment is required.
Last updated
Replacement strings follow JavaScript String.replace rules. Numbered captures can be referenced with $1 and $2, the complete match with $&, and named captures with the platform's named-group replacement syntax.
A regular expression without g replaces only the first matching occurrence. Add g when the transformation must apply to every match in the source text, and combine it with flags such as i or m when the matching rules require them.
Replacement happens only in the output preview. The original input remains editable in the browser, so you can test cleanup patterns against logs, code, configuration, or copied text without sending the source to a remote service.
Two capture groups reverse a first and last name with native JavaScript replacement tokens.
/(Ada) (Lovelace)/
$2, $1
Ada LovelaceLovelace, AdaCommon questions
Add the g flag. Without g, JavaScript regular-expression replacement changes only the first matching occurrence.
Yes. JavaScript replacement strings support numbered captures such as $1 and $2 as well as other native replacement tokens.
No. The tool produces a separate output preview while the original source remains in the input editor.
Debugging a specific Regex issue? Browse Regex troubleshooting.