Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

How-to

How to find and replace using patterns

Tick regular expressions in Find and Replace in Write by Zaweba to match patterns such as dates or codes, and use $1 in the replacement to reuse what matched.

How to find and replace using patterns

Open Find and Replace in Write by Zaweba and tick the regular expressions box. The Find box then takes a pattern rather than plain words, so one search can match every date, every phone number or every reference code in the document. In the Replace box, $1, $2 and so on put back the parts the pattern captured, which lets you rearrange text as well as change it.

When a plain search is not enough

Ordinary find and replace is perfect for swapping one word for another. It struggles when the text you want to change varies. Every date written as 03/11/2026 that should read 3 November 2026. Every double space after a full stop. Every reference like REF-0142 that should lose its prefix. A pattern describes the shape of the text rather than the exact letters, so it catches them all.

A few patterns to start with

Regular expressions are a small language of their own, used in many programs. A handful of pieces go a long way. A dot matches any single character. \d matches any digit and \s any space. A plus sign means one or more of the thing before it, and a star means none or more. Square brackets give a choice of characters, so [aeiou] matches any vowel. Round brackets capture a part of the match so you can reuse it.

So \d+ finds any run of digits, and a pair of spaces followed by a plus sign finds two or more spaces in a row. Replace that with a single space and the whole document is tidied in one go.

Rearranging with $1 and $2

Capturing is where patterns really help. Suppose a list of names is written as Surname, First name and you want First name Surname. A pattern that captures the word before the comma as the first group and the word after it as the second group can be replaced with $2 $1, and every name in the list swaps round.

The same idea turns 2026-11-03 into 03/11/2026, or wraps every reference code in brackets. Write fills in each $1 and $2 from the text the pattern matched, one match at a time.

Working safely

Patterns are powerful, so test before you replace everything. Use Find on its own first and step through a few matches to see that the pattern catches what you expect and nothing else. Then replace one or two and look at the result before replacing the rest.

Match case and Whole word still apply with regular expressions ticked, which helps keep a pattern from catching parts of longer words. If you make a mistake in the pattern, such as a bracket that is never closed, Write reports that the pattern is broken rather than crashing, so you can correct it and try again.

If a replacement goes wrong, Ctrl+Z puts things back, and Write keeps unlimited undo.

When to use something else

Patterns change text. They do not change formatting. To make every heading look the same, use styles. To copy a look from one paragraph to another, use the format painter. To turn a block of tab or comma separated lines into a table, use Convert text to table.

For cleaning up text pasted from emails and web pages, though, a couple of well-chosen patterns in Write by Zaweba can save an hour of hand editing.