In this article
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.
The regex symbols worth learning
| Pattern | Matches |
|---|---|
\d | any digit 0 to 9 |
\s | any space, tab or line break |
\w | a 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
| Job | Find | Replace 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.
Related clean-up tools
- For general whitespace mess, Remove Extra Spaces needs no patterns at all.
- For duplicates, use Remove Duplicate Lines.
- To see exactly what changed, paste before and after into Text Compare.
Everything runs in your browser; your text is never uploaded.
Frequently asked questions
What is a regular expression?
A pattern that matches text, used to find and replace many variations at once.
What does the dot mean in regex?
It matches any single character except a line break.
How do I match a number?
Use \d for one digit or \d+ for one or more digits.
Why does my regex match too much?
Patterns like .* are greedy. Use .*? to match as little as possible.
Should I test regex before replacing?
Yes. Test on a copy of your text first, because one wrong pattern can change many lines.
What does a dot mean in regex
A dot matches any single character. To find a real full stop, write \. with a backslash.
What does $1 mean in the replace box
It inserts whatever the first set of round brackets matched, so you can reorder or reuse parts of the text.