How to use it· 4 steps
- Paste your text, or open a text file.
- Type what to find and what to replace it with — leave the replacement empty to delete every match.
- Choose plain text or regular expression, and whether case and whole words matter.
- Check the highlighted preview, then copy or download the result.
Step by step
How to use the find and replace text
- 1Paste your text, or open a text file.
- 2Type what to find and what to replace it with — leave the replacement empty to delete every match.
- 3Choose plain text or regular expression, and whether case and whole words matter.
- 4Check the highlighted preview, then copy or download the result.
Plain text or regular expression
In plain mode every character means itself. Search for “3.5 (approx)” and exactly that is found, full stop and brackets included, which is what you want for words, names, phrases and code. Most find-and-replace jobs need nothing more.
Regular expression mode turns the search into a pattern: \d+ finds any run of digits, [ \t]+$ finds spaces at the ends of lines, colou?r finds both spellings. It runs on the JavaScript regular expression engine built into your browser, so a pattern that works here behaves the same in JavaScript code. As in a code editor, ^ and $ mean the start and end of each line rather than of the whole text, so finding ^ and replacing it with “- ” puts a dash in front of every line.
Patterns written for other languages usually work. Where a pattern escapes characters that JavaScript's strict Unicode mode rejects — \- or \# outside brackets, common in patterns copied from PHP or Python — it is accepted in the older, lenient mode rather than refused. Features JavaScript does not have, such as possessive quantifiers and atomic groups, are reported as errors with the engine's own message.
Rearranging with capture groups
Brackets in a pattern capture what they match, and the replacement can put it back with $1, $2 and so on. Finding ^(\w+), (\w+)$ and replacing with $2 $1 turns “Lovelace, Ada” into “Ada Lovelace” on every line; (\d{4})-(\d{2})-(\d{2}) replaced with $3/$2/$1 turns 2024-01-15 into 15/01/2024.
Named groups make longer patterns readable: (?<year>\d{4}) is put back with $<year>. $& inserts the whole match, so a replacement of [$&] wraps every match in square brackets, and $$ writes a literal dollar sign. These follow JavaScript's String.replace rules exactly, down to the rarely used $` and $' for the text before and after the match.
In plain mode a dollar sign in the replacement is just a dollar sign, so prices and shell variables come through untouched.
Whole words, case and first-only
Whole words only stops “cat” matching inside “concatenate”. It checks that a match is not touching a letter, digit or underscore on either side — in any script, so it works for “café” and for Hindi or Arabic words, not only English. JavaScript's own \b knows only A to Z, a to z, the digits and the underscore, which is why it misfires on accented words.
Matching ignores case unless you tick Match case, as in most editors. Replace all is on by default; untick it to change only the first match, which is useful for a heading or the first mention of a name. The count still reports how many matches there are in total.
Why a bad pattern cannot freeze this page
The regular expression engines in browsers work by backtracking: when part of a pattern fails, they go back and try the other ways the earlier parts could have matched. For most patterns that is fast. For a pattern with nested repetition over the same characters — (a+)+$, or (\w+\s?)*$ — the number of ways to try doubles with every extra character, and on a string that nearly matches, thirty characters can take minutes. This is catastrophic backtracking, a well-known way to hang a web page or take down a server.
Limiting the size of the input does not prevent it, because the cost comes from the pattern rather than the length of the text. And a pattern running on a page's main thread cannot be interrupted: the tab simply stops responding. So this tool runs regular-expression searches in a background worker and gives each one two seconds. If a search has not finished by then the worker is shut down — the one thing that reliably stops a runaway match — and you are told that the pattern is backtracking and what usually causes it. The page stays responsive throughout, and plain-text searches, which cannot backtrack, run instantly.
The fix is almost always to make the repeated part more specific, so that there is only one way to match each character: \w+(?:\s\w+)* instead of (\w+\s?)*.
Checking the changes before you use them
The preview shows your text with each match struck through in red and its replacement in green, so a pattern that catches too much is obvious before the result goes anywhere. For very long texts it shows the first 500 changes and the opening 30,000 characters; the result box always contains every replacement.
Use as input copies the result back into the text box, so replacements can be chained — strip trailing spaces, then normalise dates, then swap a name — with a preview at every step.
Answers
Frequently asked questions
How do I use capture groups in the replacement?
Turn on Regular expression, put brackets around the parts you want to keep, and refer to them in the replacement as $1, $2 and so on — or name a group with (?<name>…) and use $<name>.
How do I replace line breaks?
In regex mode, \n matches a line break: find \n and replace it with a space or a comma. To join lines into paragraphs, the remove line breaks tool also handles hyphens and paragraph breaks.
Why does my pattern from Python or PHP not work?
JavaScript's syntax differs in places: it has no possessive quantifiers or atomic groups, and named groups are written (?<name>…) rather than Python's (?P<name>…). Most everyday patterns work unchanged.
Why was my search stopped?
It ran for more than two seconds, which almost always means catastrophic backtracking from nested repetition. Make the repeated part of the pattern more specific and try again.
Is the search case-sensitive?
Not by default. Tick Match case to make it case-sensitive.
Can I replace text inside a Word document or a PDF?
Not directly — this works on plain text. Copy the text out, make the replacements and paste it back, or convert the file to text first.
Is my text uploaded?
No. Searching and replacing happen in your browser, including the regex worker.