Text Tools

Find and Replace with Regular Expressions – A Beginner’s Guide

Plain find and replace changes one word to another. Regular expressions (regex) let you change patterns – every phone number, every date, every line start – in one go.

In this article
  1. Start simple
  2. The regex symbols worth learning
  3. Recipes for real jobs
  4. Groups and $1, $2 explained
  5. Greedy matching
  6. Special characters need a backslash
  7. Test on a copy
  8. Related clean-up tools

Start simple

For most jobs you do not need regex. In Find and Replace, type the word, type the replacement and choose:

  • Case-sensitive – “Apple” (the company) but not “apple” (the fruit).
  • Whole word – replace “cat” but not the “cat” inside “category”.

The tool tells you exactly how many replacements were made, so you can check it did what you expected.

Find and ReplaceFind and replace words or phrases across any text. Match case, whole words only or use regular expressions with capture groups. Shows match count.
Open the free tool

The regex symbols worth learning

PatternMatches
\dany digit 0–9
\sany space, tab or line break
\wa letter, digit or underscore
.any character
+one or more of the previous item
*zero or more of the previous item
^ and $start and end of a line
( )a group you can reuse as $1, $2

Recipes for real jobs

JobFindReplace with
Collapse multiple spaces {2,}one space
Remove all digits\d+(nothing)
Add “- ” to the start of every line^-
Swap “Surname, Firstname” to “Firstname Surname”(\w+), (\w+)$2 $1
Change dates 2026-11-20 to 20/11/2026(\d{4})-(\d{2})-(\d{2})$3/$2/$1
Hide email addresses[\w.+-]+@[\w-]+\.[\w.]+[email removed]
Turn a comma list into lines,\s*\n

Groups and $1, $2 explained

Round brackets do two jobs: they group part of a pattern, and they remember what that part matched. In the replacement, $1 means “whatever the first group matched”, $2 the second, and so on. That is how the date recipe above rearranges year, month and day without knowing the actual numbers – it simply moves the remembered pieces into a new order.

Greedy matching

By default, .* matches as much as possible. In “<b>one</b> and <b>two</b>”, the pattern <b>.*</b> matches the whole line, not just the first tag. Add a question mark – .*? – to match as little as possible instead. This one detail explains most “why did it replace everything?” surprises.

Special characters need a backslash

Symbols like . + * ? ( ) [ ] { } ^ $ | and the backslash itself have special meanings. To find a real full stop or bracket, put a backslash in front: \. finds a full stop, \( finds an opening bracket. If your pattern has a mistake, the tool shows a helpful message instead of failing silently.

Test on a copy

Regex is powerful – one pattern can change thousands of places. Work on a copy of your text, check the replacement count, and read a few changed lines. If the count is far higher than you expected, your pattern is matching more than you intended.

Everything runs in your browser; your text is never uploaded.

Find and ReplaceFind and replace words or phrases across any text. Match case, whole words only or use regular expressions with capture groups. Shows match count.
Open the free tool
Keep reading

Related articles

All articles
Text

How to Fix Messy Text Copied from PDFs and Websites

Paste text from a PDF and every line breaks in the wrong place; paste from a website and odd gaps appear. Here is what causes the mess and how to clean it fast.

3 min read
Text

How to Clean Email, Phone Number and Keyword Lists in Seconds

Lists collected from several places always contain repeats. Sending to the same person twice or paying for duplicate keywords is avoidable – here is how.

3 min read
Text

Title Case, Sentence Case, camelCase and More – When to Use Each

Capital letters change how professional text looks, and in code they can break things. Here is a practical guide to every common case style.

3 min read