Guide

How to Find and Replace Text (Including With Regex)

Master find-and-replace from simple swaps to regex patterns, and learn safe habits that prevent costly mistakes.

Find-and-replace locates every occurrence of a search string and swaps it for a replacement. Simple mode matches literal text; regex mode matches patterns, which is far more powerful but demands care.

Simple vs. regex replacement

In simple mode, searching for "cat" replaces every literal "cat" — including inside "category". Regex mode lets you match patterns: word boundaries, digits, repetition, alternatives. Searching for "\bcat\b" with regex replaces only the standalone word "cat", leaving "category" untouched.

Useful regex patterns for replacement

  • \b — word boundary, to match whole words only.
  • \d+ — one or more digits.
  • \s+ — one or more whitespace characters.
  • .*? — any characters, non-greedy.
  • (abc|xyz) — either "abc" or "xyz".
  • ^ and $ — start and end of a line.

How to use find-and-replace safely

  1. Back up your original text before a large replace.
  2. Start with case-sensitive matching to avoid unintended swaps.
  3. Use word boundaries (\b) when replacing common words.
  4. Review a preview of matches before applying if available.
  5. Test regex on a small sample first.

Examples

Replacing "colour" with "color" in simple mode swaps every occurrence — useful for British-to-American spelling. With regex, replacing "\b\d{4}\b" with "YEAR" turns every standalone 4-digit number into "YEAR", ideal for anonymising dates in a transcript.

When find-and-replace is useful

  • Bulk-renaming terms across a document or codebase.
  • Standardising spelling, capitalisation, or formatting.
  • Redacting or anonymising sensitive patterns.
  • Cleaning imported data before analysis.

Put it into practice

Use the Find & Replace right now — free, in your browser, no sign-up required.

Try the Find & Replace