Regex Replace Online — Find and Replace With Capture Groups
Write the pattern, write the replacement, and watch the result update line by line. Backreferences, named tokens and match counts are shown before you commit the change to a file, a migration, or an editor macro.
- Use `$1`, `$2` or `${name}` in the replacement to reuse captured text.
- Check first-or-all mode: without the `g` flag only the first match is replaced.
- Escape literal dollar signs in the replacement as `$$`.
This tool runs entirely in your browser. Your patterns and text are not uploaded, stored, or logged.
Preview before you replace
The damage from a bad replace is proportional to how little you could see of the result. A live preview shows the exact output, including the whitespace and separators that a scrollback hides, so an over-greedy pattern is obvious before it rewrites a config file or a database dump.
Keep the input small while iterating. Paste two or three representative lines, get the pattern right, then paste the whole document. Reviewing the diff afterwards is a habit worth keeping even when the preview looked correct.
Capture groups instead of string surgery
Replacement templates are the reason regex beats repeated manual edits. Capturing the parts you want to keep and re-emitting them in a new order is declarative: the pattern states the shape of the input, the template states the shape of the output.
- Reformat dates: `(?<year>\d{4})-(?<month>\d{2})` becomes `${month}/${year}`.
- Normalize separators by capturing the value and re-emitting it with a fixed delimiter.
- Wrap matches in markup or quotes without retyping the matched text.
Where regex replace goes wrong
Three mistakes cover most of it: an unanchored pattern that also matches inside longer tokens, a greedy quantifier that spans lines it should have stopped at, and a replacement that loses a group because the numbering shifted when the pattern changed. All three are visible in a preview and invisible in a dialog that only reports a count.
Frequently asked questions
How do I reference a captured group in the replacement?
Use `$1`, `$2` and so on for numbered groups, or `${name}` for named groups. `$$` inserts a literal dollar sign, and `$&` inserts the whole match.
Why was only one occurrence replaced?
The pattern is missing the global flag. Without `g`, replace stops after the first match; switch the mode to replace all, or add the flag.
Is my text uploaded when I use this replace tool?
No. The pattern, the replacement string and the input text stay in your browser and are never sent anywhere or stored.