Find and replace in bulk: regex, capture groups, and a preview count
Paste the source text, enter what to find and what to replace it with. Turn on Regex to use a pattern and reference capture groups as $1. Check the match count first, then run Replace all. The input is never rewritten; only the output changes.
Open the tool:Find and Replace
When bulk replace earns its keep
Exported data often arrives with a mix of full-width punctuation, runs of spaces, and non-breaking spaces (U+00A0). Fixing dozens of spots by hand is slow and easy to get wrong, while one pattern cleans the whole batch.
Format normalisation is the other common job: turning 2024-01-05 into 2024/01/05 everywhere, or prefixing every phone number with a country code while keeping the original digits in a capture group.
Then there is targeted editing: changing status code 500 to 503 in a log without touching other numbers. Boundary checks in the pattern are far safer than replacing every occurrence of a substring.
- Clean up mixed full-width punctuation, repeated spaces, and U+00A0
- Normalise dates, phone numbers, and IDs
- Add a prefix or suffix while keeping the matched value
- Replace one pattern without touching similar text
How to get it right
Run the match count before replacing. It exposes both failure modes at once: a pattern that is too broad counts text you did not mean to touch, and one that is too narrow matches nothing, making the replace a no-op.
Group with parentheses and reference groups as $1, $2 in the replacement, while $& stands for the whole match. Plain-text mode uses the same replacement syntax, so $& expands there too. For a literal dollar sign, write $$.
Referencing a group that does not exist is not an error: with one pair of parentheses, $2 is left in the output as-is. If $2 appears in your result, the group number is usually off by one.
Patterns are compiled with g and optional i only, with no m, s, or u. As a result, ^ and $ anchor the whole text rather than each line, . does not cross newlines, \p{L} is read as a literal letter p, and \u{1F600} is read as the text u{1F600}. For Unicode properties or code point escapes, write a surrogate pair such as \uD83D\uDE00 or paste the character itself.
A pattern that fails to compile means no replacement runs and the output keeps its previous contents, so the source is safe. The catch is that the error may only appear in the browser console, which makes the page look unresponsive. Check for unbalanced parentheses or brackets first.
Greediness is the other classic trap: <b>.*</b> runs from the first <b> to the last </b> and swallows everything between them, while <b>.*?</b> matches each pair separately. Validate on a small sample before running the replace across the whole document; that is much cheaper than undoing it.
- Preview the match count before replacing
- Capture groups are numbered by opening parenthesis
- Write $$ when you need a literal dollar sign
- No m, s, or u: ^ and $ are not per-line and . does not cross newlines
Alternatives and limits
When you need per-line anchors, the s flag, or Unicode properties, use your editor's regex replace (VS Code, Sublime) or the command line with perl -0777 -pe or sed. They support the flags and handle larger files.
If the rule needs conditions, such as different replacements per case or a computed value, write a script. Long patterns are hard to verify and easy to break on the next edit.
This tool treats everything as plain text. It does not parse HTML, CSV, or JSON, so editing one attribute or one column can still hit the wrong text, and a multi-megabyte document will visibly lag. It is a text-cleaning tool, not a data migration tool.
- Multiline or s flag → editor or perl/sed
- Conditional or computed replacements → a script
- Structured data → parse it first, do not regex it
FAQ
Can a bad regex corrupt my original text?
No. The input box is never written back and the result appears only in the output box. If the pattern fails to compile, the replacement does not run at all and the output keeps its previous contents. The real problem is that the error may only show up in the browser console, so the page can look unresponsive; a pattern with an unclosed parenthesis or bracket is the usual cause.
Why does \p{L} or \u{1F600} match nothing?
The pattern is built with new RegExp using g and optional i only, without the u flag. So \p is treated as a plain letter p and \u{1F600} as the literal text u{1F600}: no error, but no match. To use Unicode properties or code point escapes, rewrite them as a surrogate pair such as \uD83D\uDE00, or paste the actual character.
What do $1 and $& mean, and what happens if there is no second group?
$1 references the first capture group, $& is the entire match, and $$ produces a literal dollar sign. If you reference a group that does not exist — $2 with only one pair of parentheses — $2 is left in the result as text. Plain-text mode uses the same replacement syntax, so $& expands there as well.
Related tool:Find and Replace