Find and replace text
Replace words or patterns across a block of text, and see how many matches there are before you replace.
Runs entirely in your browser
JavaScript regular-expression syntax. Use $1, $2 for groups and $& for the whole match in the replacement.
Type what to find.
Text up to about 5 MB. Regex patterns that run longer than 2 seconds are stopped.
How to find and replace text
- Paste your text into the box, or open a .txt file.
- Type what to find and what to replace it with. The number of matches updates as you type.
- Press Replace all, then copy the result or download it.
Replacing text in bulk
Find and replace changes every occurrence of a word or pattern in one pass. The match count updates while you type, so you can see how far a change reaches before you apply it, and the result appears in a separate box so your original text is never overwritten until you choose "Use result as text".
Regular expressions let you describe a shape rather than a fixed string: a run of digits, a date, a word followed by a comma. Groups in brackets can be rearranged in the replacement with $1, $2 and so on. Because a badly written pattern can run for a very long time, patterns are executed in a background worker that is stopped after two seconds.
Tips
- Build and debug a pattern first in the Regex tester, which lists every match and its groups.
- Change capitalisation with the Case converter.
- Check the edit with Compare text.
- Remove repeated lines with Remove duplicate lines.
Questions
Is the search literal or a pattern?
Literal by default: what you type is matched exactly, including characters like . and *. Turn on "Regular expression" to use JavaScript regular-expression syntax.
How do I use groups in the replacement?
In regular-expression mode, $1, $2 and so on insert the text matched by the first, second (and so on) bracketed group, $& inserts the whole match and $
What does Whole word do?
It only matches the search text when it is not part of a longer word, so finding cat does not match category. In literal mode, letters, digits and underscore count as word characters in any script. In regular-expression mode it wraps your pattern in word boundaries (\b), which only recognise A-Z, digits and underscore.
What is the 2-second limit?
Some patterns, such as (a+)+$, can take an extremely long time on certain text. Regular-expression mode runs in a separate background worker; if it has not finished after 2 seconds it is stopped and you are told the pattern took too long, so the page never freezes.
Does the pattern run across lines?
In regular-expression mode ^ and $ match at the start and end of every line, and the dot does not match a line break. Case is ignored unless Match case is on.
Is my text uploaded?
No. Everything runs in your browser and nothing is stored or sent.