Back to All Tools

Find & Replace

Find and replace text instantly. Supports regex, $1 groups and whole words.

100% Private — Your data never leaves your browser. Everything runs locally on your device.

How the search works

Paste your text, type what to find and what to put in its place, then click Replace All. The new text appears in the Result box with the number of replacements. Your original text stays in the top box. The result does not update while you type, so click Replace All again after each change. If the Find box is empty, nothing happens.

Case Sensitive and Whole word

Both boxes are unticked at the start. With Case Sensitive off, capital and small letters are treated the same. With Whole word off, a search can also change parts of longer words. Here is cat replaced with dog:

Text: Cat cat CAT category concatenate
Both off: dog dog dog dogegory condogenate (5 replacements)
Whole word on: dog dog dog category concatenate (3 replacements)
Whole word and Case Sensitive on: Cat dog CAT category concatenate (1 replacement)

Whole word means the match must not have a word character right before it or right after it. A word character is a letter in any language, a digit, the underscore _, or a combining mark such as the vowel signs in Nepali. So whole-word search works with accented and non-Latin words. café matches café but not cafés, and नमस्ते matches नमस्ते but not नमस्तेजी. An apostrophe or a hyphen is not a word character, so cat is still found in cat's and cat-like.

This is more reliable than \b in a regex. \b only knows the letters a to z, digits and the underscore. So \bcafé\b skips the word café but matches the start of cafés. Whole word needs a browser from 2023 or later, such as Safari 16.4 or newer. An older browser shows an error message instead.

Every match becomes exactly what you typed. Cat at the start of a sentence becomes dog, with a small d.

Plain text or regex

With Use Regex off, every character you type is searched for as it is. $5.00 finds only $5.00, and a dot finds only a dot. You do not need to escape anything. The replacement is plain text too, so $1 or $5.00 is inserted exactly as typed.

With Use Regex on, the Find box is a JavaScript regular expression, a short pattern language for describing text. \d+ means one or more digits, \s means any space, tab or line break, and . means any character. Two settings are fixed:

When Whole word is also ticked, the pattern is checked with stricter rules. (This is the u flag, for Unicode.) A backslash is then only allowed before a special character. For example, \: is an error, and so is \- outside square brackets. Write : and - instead. In return, patterns such as \p{L} (any letter) work.

If the pattern has a mistake, such as a ( that is never closed, a red message appears under the options. The result is not changed.

Putting found text back with $1

With Use Regex on, the Replace With box understands the same codes as the replace() function in JavaScript:

CodeInserts
$&The whole match.
$1, $2 … $99What the first, second … pair of round brackets matched.
$<name>What a named group (?<name>…) matched.
$$One dollar sign.
$` and $'All the text before the match, or all the text after it.

For example, Find (\w+) (\w+) with Replace $2 $1 turns John Smith into Smith John. If a group number does not exist, the code is inserted as typed. With only one pair of brackets, $2 stays $2.

With Use Regex off, none of these codes work. The replacement is inserted exactly as typed.

Line breaks and tabs in the replacement

The Replace With box is one line. To put a line break in the replacement, tick Use \n and \t in Replace. Then \n becomes a line break and \t becomes a tab. Write \\ for one real backslash, so \\n gives a backslash and the letter n. Other backslash codes stay as typed. This works with Use Regex on or off.

The box is unticked at the start. Then \n in Replace With is inserted as a backslash and the letter n. In the Find box, \n finds a line break only when Use Regex is on.

Recipes that work

All of these need Use Regex ticked. Leave Replace With empty where it says (empty).

TaskFindReplace WithExample
Swap first and last name on each line^(\S+) (\S+)$$2, $1John Smith → Smith, John
Change the date order(\d{4})-(\d{2})-(\d{2})$3/$2/$12024-03-15 → 15/03/2024
Wrap each line in an HTML list item^.+$<li>$&</li>apple → <li>apple</li>
Put a dollar sign before prices(\d+\.\d\d)$$$14.99 and 12.50 → $4.99 and $12.50
Remove spaces at the start of lines^[ \t]+(empty)Removes the indent from every line.
Remove spaces at the end of lines[ \t]+$(empty)Removes spaces and tabs at the end of every line.
Remove empty lines^\s*\n(empty)Removes blank lines, and lines with only spaces, between lines of text.
Turn a list into one line\n, (comma and space)apple, banana, cherry on three lines → apple, banana, cherry
Put each item of a comma list on its own line,\s*\n, with Use \n and \t in Replace tickedapple, banana, cherry → three lines
Fix double spaces[ ]{2,} (a space inside square brackets)one spacea b c → a b c
Remove reference marks copied from Wikipedia\[\d+\](empty)Paris is big.[1] It is old.[23] → Paris is big. It is old.
Change long dashes to hyphens[–—]-2020–2021 → 2020-2021

For double spaces, a plain search for two spaces is not enough. It replaces pairs once, so four spaces become two. a b c becomes a b c. The regex above fixes any number of spaces in one click.

Common mistakes

If a pattern does not do what you expect, try it in the Regex Tester. It highlights each match, so you can see what will be replaced before you replace it. It does not replace text itself. To make it behave like this tool, tick its m box, leave s unticked, and tick i when Case Sensitive is off here. It has no Whole word option and no u flag. Both tools run in your browser, and your text is not uploaded.

Frequently Asked Questions

Can I use $1 or $2 in the replacement?

Yes, with Use Regex on. $1, $2 and so on insert what each pair of round brackets matched. $& inserts the whole match, $<name> inserts a named group, and $$ inserts one dollar sign. For example, Find (\w+) (\w+) with Replace $2 $1 turns John Smith into Smith John. With Use Regex off, the replacement is plain text, so $1 and $5.00 are inserted exactly as typed.

How do I replace whole words only?

Tick Whole word. Then cat no longer matches inside category or concatenate. A match must not have a letter, digit, underscore or combining mark right before it or right after it. Letters from any language count, so café and नमस्ते work too. An apostrophe or a hyphen counts as the edge of a word, so cat is still found in cat's and cat-like.

Can I replace text with a line break?

Yes. Tick Use \n and \t in Replace. Then \n in the Replace With box becomes a line break and \t becomes a tab. For example, with Use Regex on, Find ,\s* and Replace \n put each item of a comma list on its own line. Write \\ when you need one real backslash.

Do ^ and $ match at each line?

Yes. With Use Regex on, ^ means the start of each line and $ means the end of each line. So ^[ \t]+ with an empty Replace With box removes the indent from every line. This setting is always on.

How do I delete every match?

Leave the Replace With box empty and click Replace All. Every match is removed. For example, \[\d+\] with Use Regex on removes reference marks such as [1] and [23] from text copied from Wikipedia.

What happens if my regex has a mistake?

A red message appears under the options and says what is wrong, for example a bracket that is never closed. The result is not changed. With Whole word ticked the rules are stricter, so an extra backslash such as \: is also an error.

Is my text uploaded anywhere?

No. The search and replace is done by JavaScript in this page, inside your browser. Your text is not sent to a server.