Skip to the content

Find and Replace

Replace a word or pattern everywhere in a text, with optional regular expressions.

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

The four switches

Match case is off to begin with, so cat also finds Cat and CAT. The replacement is always inserted exactly as you typed it; its capitals are not adjusted to the word it replaces.

Whole words only stops cat from matching inside concatenate. A word ends where the letters, digits and underscores end, and that holds for every alphabet: né is not found inside néant.

Read \n as a line break and \t as a tab is for the two characters you can't type in a one-line field. Replace , with \n and a comma-separated list becomes one item per line. With this switch on, write \\ when you mean a real backslash.

Regular expression turns the search text into a pattern. More on that below.

Every match is marked in a copy of your text before you take the result, and the count tells you whether the search found as many as you expected. Use as input carries the result back up, for a second replacement on top of the first.

Patterns worth knowing

To do thisFindReplace with
Collapse repeated spacestwo spaces and a +one space
Turn "Lovelace, Ada" into "Ada Lovelace"(\w+), (\w+)$2 $1
Remove spaces at the end of lines[ \t]+$nothing
Delete empty lines^[ \t]*\nnothing
Put something in front of every line^>
Rewrite 2025-03-14 as 14/03/2025(\d{4})-(\d{2})-(\d{2})$3/$2/$1

In the replacement, $1 and $2 stand for what the first and second pair of brackets matched, $& for the whole match and $$ for a dollar sign.

Which kind of regular expression

Patterns follow JavaScript syntax, because your browser's own engine runs them. Three things are always switched on: every match is replaced, ^ and $ work at the start and end of each line, and Unicode mode is used, so . sees an emoji as one character and \p{L} matches a letter of any alphabet. A . does not match a line break; use [\s\S] for "anything at all".

Two things trip people up:

  • Unicode mode is strict about backslashes. One in front of a character that doesn't need it, as in \" or \:, is an error. Leave it out.
  • \b and \w only know a to z, digits and the underscore. \bné\b misses the word "né" and finds the first two letters of "néant" instead. Whole words only does not have that problem, and it can be combined with a pattern.

Limits

A search that is still running after a second is stopped, and so is a replacement that would make the text more than 20 million characters longer. The clock is checked between matches. A pattern with nested repeats, such as (a+)+$, can still keep the browser busy inside a single match on the wrong text; if the page stops responding, close the tab and simplify the pattern.

See all 9