Find and Replace
Text Tools · Added
Paste the text, say what to look for and what to put in its place. Plain-text mode takes every character literally, so brackets and dots search for themselves. Regular expression mode hands the pattern to your browser own engine, with capture groups available in the replacement. Either way the original stays on screen beside the result, so you can adjust the pattern and try again.
How to use the find and replace
- 1Paste or type the text you want to change into the first box.
- 2Choose Plain text for a literal search, or Regular expression for a pattern.
- 3Fill in what to find and what to replace it with. Leave the replacement empty to delete every match.
- 4Set the options: match case, whole words only, first match or all of them.
- 5Read the match count and the preview list, then copy or download the updated text.
Examples
A literal replacement
- Input
- Find: Acme Pvt Ltd — Replace: Acme Private Limited
- Result
- Every occurrence changed, with a count of how many
In plain-text mode nothing in the search box is treated as a pattern, so a company name containing a full stop or brackets works as typed.
Reordering with capture groups
- Input
- Regex: (\\w+), (\\w+) — Replace: $2 $1
- Result
- Sharma, Ravi becomes Ravi Sharma
$1 and $2 insert what the brackets captured, which is how a list of surname-first names is flipped in one pass.
Deleting a pattern
- Input
- Regex: \\s{2,} — Replace: (empty)
- Result
- Every run of two or more spaces removed
An empty replacement deletes rather than replaces. Add a single space instead to collapse runs down to one.
About the find and replace
The two modes, and why both exist
Literal search is what people want most of the time and what most tools make hardest. You know the exact string, you want it gone, and you do not want to think about which of its characters are special. Escaping the pattern before it reaches the engine costs nothing and removes an entire category of confusion, which is why plain text is the default here.
Regular expressions earn their complexity when the thing you are matching has a shape rather than a value. Every date in a file, every trailing space, every phone number with an inconsistent separator, every occurrence of a word that is not part of a longer word. None of those can be expressed as a literal string, and all of them are a few characters of pattern.
The capture group is the feature that turns find-and-replace from deletion into restructuring. Bracketing part of a pattern remembers what it matched, and referring to it in the replacement as a numbered slot lets you reorder, reformat or wrap it. Flipping a comma-separated name, turning a date from one order into another, wrapping a bare URL in a link — all the same one-line move.
Habits that stop a replacement going wrong
Look at the match count before you look at the output. It is the fastest check there is: if you expected a dozen and it says four hundred, the pattern is matching more than you meant, and the preview list underneath will usually show why in the first line. Finding that out before the replacement is applied costs nothing.
Use whole words when replacing a short one. Replacing cat with dog across a document also turns catalogue into dogalogue and duplicate into dupligate, which is the classic demonstration of why the option exists. The boundaries are added around the whole pattern rather than around each alternative, so an expression like cat or car is bounded as a unit.
For anything irreversible, work in stages. Replace once, read the result, then paste the result back in and replace again for the next transformation, rather than trying to express three changes in one clever pattern. Each step is easy to verify and easy to abandon. The original stays untouched in the box above throughout, which is what makes that loop cheap here.
Frequently asked questions
When should I use plain text rather than a regular expression?
How do I insert a line break in the replacement?
Why does a dollar sign in my replacement disappear?
Is my text uploaded anywhere?
Related tools
Text Cleaner
Text Tools
Strip extra spaces, blank lines, line breaks, HTML tags, punctuation and smart quotes.
Remove Duplicate Lines
Text Tools
Strip duplicate lines from a list, with options for case sensitivity and trimming.
Regex Tester
Developer Tools
Test regular expressions live with highlighted matches, capture groups and replace.