How to find and replace text: recipes that work

To find and replace text, enter the word to find and its replacement, decide whether case and whole words matter, and check every change before you save. For more than one change, write several rules that run in order, and use regular expressions for patterns such as dates, numbers or repeated spaces. This guide collects the recipes people need most, ready to copy into the tool below.

4 min read

The three questions before every replacement

Most find and replace mistakes come from replacing too much. Before you press anything, answer three questions. Should case matter? Searching for apple without Match case also finds Apple and APPLE, which is what you want for a typo but not for a brand name. Should only whole words match? Without Whole word, replacing cat also changes catalog and bobcat. Is this a fixed word or a pattern? A fixed word is plain text; a pattern such as any date or any number needs a regular expression.

The tool on this page shows each change highlighted and counts the matches per rule, so you can see at once whether a rule matched 3 times or 3,000 times. A count that is much higher than expected is the best warning sign.

Try it here: Find and Replace

Open the full tool page

Everyday recipes without regex

Plain text rules cover most daily jobs. Special characters such as the dot, the dollar sign or brackets are treated literally in plain mode, so you do not need to escape anything.

TaskFindReplace withOptions
Fix a misspelled wordrecievereceiveWhole word
Rename a product everywhereModel X200Model X300Match case
Change a separator;,none
Remove a wordDRAFT (empty)Match case
Update a linkhttp://example.comhttps://example.comnone

Regex recipes for patterns

Turn on Regex for a rule to use regular expressions. Parentheses capture parts of the match, and $1, $2 and so on put them back in the replacement. In this tool \n in the replacement inserts a line break and \t a tab.

TaskFind (regex)Replace with
Collapse repeated spaces {2,}(one space)
Remove spaces at line ends[ \t]+(?=\n|$)(empty)
Date 27/10/2026 to 2026-10-27(\d{2})/(\d{2})/(\d{4})$3-$2-$1
Comma list to one item per line,\s*\n
Lines to a comma list\n,
Swap first and last name(\p{L}+) (\p{L}+)$2, $1
Delete empty lines\n{2,}\n
Remove HTML tags<[^>]+>(empty)

Plain text or regex: which to choose

Start with plain text whenever the text you look for is always the same. It is faster to write, special characters need no escaping and it cannot accidentally match more than you meant. Switch to regex only when the text varies but follows a pattern: any number, any date, any amount of spaces, any word at the start of a line.

A good habit is to build a regex step by step. Write the simplest version, check the highlighted matches, then make it stricter. If you are unsure what a symbol means in a pattern, the regex cheat sheet linked from this page lists the common ones, and the regex tester shows every match with its groups before you replace anything.

Several replacements in the right order

When you need more than one change, order matters. Rules run from top to bottom and each one sees the result of the rules above. Suppose you want to swap two words, red and blue. If the first rule replaces red with blue and the second blue with red, everything ends up red. The fix is a temporary placeholder: red to @@TMP@@, then blue to red, then @@TMP@@ to blue.

Order also matters for cleanup. Remove HTML tags before you collapse spaces, because removing tags often leaves double spaces behind. Normalize line breaks before you join lines. Use the arrows next to each rule to move it up or down, and watch the counts change.

Working with files

Open a text file to load it into the editor; the download keeps its name and extension. To apply the same rules to many files, such as a folder of subtitles, CSV exports or HTML pages, choose Apply to files. Each file is processed with the same rules, you see the number of changes per file, and you download them together as a ZIP. Nothing is uploaded: the files are read and written in your browser.

Only plain text files work this way. Word documents, Excel workbooks and PDF files store text inside a compressed or binary format, so convert them to text first or use the program that created them.

Avoiding the classic mistakes

  • Replacing a short word without Whole word, which changes parts of longer words.
  • Forgetting that plain mode ignores case by default, which also changes capitalized names.
  • Using a regex dot to mean a period: in regex . means any character, so write \. for a real dot.
  • Greedy patterns such as <.*> that swallow everything between the first < and the last >. Use <[^>]+> instead.
  • Swapping two words with two rules and no placeholder.
  • Patterns that can backtrack forever, such as (a+)+b. The tool stops them after two seconds and names the rule.

Step by step

  1. Paste or open your textPaste text into the input, or open a text file. For many files, prepare them in one folder.
  2. Write the first ruleEnter what to find and what to put in its place, and choose Match case, Whole word or Regex.
  3. Add more rules if neededAdd rules for further changes and order them with the arrows. Each rule shows how many matches it found.
  4. Check the highlightsRead through the highlighted result. A thin red line marks places where text was only removed.
  5. Copy or downloadCopy the result, download the file, or use Apply to files and download a ZIP.

Frequently asked questions

How do I replace a line break with a comma?

Turn on Regex, find \n and replace with a comma and a space. To go the other way, find ,\s* and replace with \n.

How do I replace only whole words?

Turn on Whole word. The tool then skips matches inside longer words, and this works for accented letters and other alphabets too.

Can I undo a replacement?

Your original text stays in the input box; only the result changes. Remove or edit a rule and the result updates at once.

Why does my regex find nothing?

Check that Regex is on for that rule, that special characters such as . ( ) [ ] ? are escaped with a backslash when you mean them literally, and that Match case is not on by mistake.

Are my files sent to a server?

No. Files are read and changed in your browser and never leave your device.