Find and Replace
Replace every match of plain text or a regular expression, with the matches highlighted.
About Find and Replace
Find and replace text in the browser using plain text or a regular expression, with every match counted, highlighted and replaced as you type.
How to use
- Choose Plain text or Regular expression.
- Type what to find and what to replace it with. Both fields take several lines, so a search can include line breaks.
- Tick "Case-sensitive" or "Whole word" if you need them. In regular-expression mode, "^ and $ match each line" and ". matches line breaks" switch on the
mandsflags. - Paste the text. After a short pause the match count, the text with its matches highlighted and the result all update.
- Copy the result, or download it as
replaced.txt.
What it does
- Replaces every match. There is no "replace first only" and no stepping through matches one at a time.
- In plain-text mode the search and the replacement are both literal:
.,*,$and\mean themselves. - In regular-expression mode the pattern is a JavaScript regular expression with the Unicode flag always on.
\p{L}works and.matches a whole emoji; in return, an unnecessary escape such as\-outside a character class is a syntax error. - In regular-expression mode the replacement understands
$1,lt;name>,amp;and$(a literal dollar sign), plus\n,\r,\tand\\. - The search ignores case unless "Case-sensitive" is ticked.
- "Whole word" accepts a match only when the characters on either side are not letters, digits, combining marks or underscores, in any script, so "café" is found as a word.
- A pattern that can match nothing, such as
x*or^, has its empty matches counted and the replacement inserted at each one. The page tells you when that happens. - The search runs in a Web Worker and is stopped after 2 seconds, so a pattern that backtracks without end cannot freeze the page.
- Limits: the first 5,000 matches are highlighted, and highlighting is switched off above 200,000 characters. The result is complete in both cases.
- It does not preserve the capitalisation of each replaced word, change the case of captured groups, or open files; paste the text in.
Example
Mode: Regular expression
Find: (\d{4})-(\d{2})-(\d{2})
Replace with: $3/$2/$1
Text: Released 2024-01-15, patched 2024-03-02.
Matches: 2
Result: Released 15/01/2024, patched 02/03/2024.
Privacy
The search runs in a Web Worker inside the browser. No request is made with the text, and nothing is stored.
Frequently asked questions
- How do I replace text with a new line?
- Switch to Regular expression mode and type \n in the Replace with field. Finding a comma and replacing it with \n puts each item of a comma-separated list on its own line. In plain-text mode, press Enter in the Replace with field instead.
- What do $1 and amp; mean in a replacement?
- $1 inserts the text captured by the first pair of parentheses in the pattern, $2 the second, and so on. lt;name> inserts a named group and amp; the whole match. They work only in regular-expression mode, where $ gives a literal dollar sign.
- Why does a regular expression make the page hang?
- A pattern with nested repeats, such as (a+)+$, can take exponential time on text that almost matches. This is called catastrophic backtracking. Here the search runs in a background worker and is stopped after 2 seconds; rewrite the pattern so its repeats cannot overlap.
- How do I find and replace whole words only?
- Tick "Whole word". A match then counts only when it is not next to a letter, digit or underscore, so searching for cat finds "cat" but not "concat" or "cats".