
Word: Replace ‘to’ in a number range with a dash
March 26, 2023Pam asked if I could help her with a wildcard search for replacing the ‘to’ in a number range (e.g. 1.65 to 2.30) with a dash (in this case, she wanted a dash (also known as a hyphen—the one on the top of a keyboard), not an en dash, which would be typical for a number range). She PROMISED she wouldn’t do ‘replace all’, and if you’re doing this, please don’t use ‘replace all’ as you may change some things that aren’t number ranges (e.g. They each gave $25 to 10 people).
These instructions are for Word for Windows; Word for Mac should be the same once you get to its Find and Replace window:
- Press Ctrl+h to open the Find and Replace window.
- Click More.
- Select the Use wildcards checkbox.
- In the Find, type: ([0-9])( to )([0-9])
(NOTE: There is a single space either side of the ‘to’) - In the Replace, type: \1-\3
(NOTE: This adds a standard dash; if you want an en dash, replace the standard dash with an en dash, which you can get by pressing Ctrl+[minus] on the number pad of a standard keyboard.) - Click Find Next, then Replace if the instance found meets your criteria. Repeat.
How this works:
- ([0-9]) represents any single numerical digit from 0 to 9
- ( to ) looks for ‘to’ surrounded by a single space either side
- \1-\3 replaces the first instance of ([0-9]) with itself (i.e. no change), then adds a dash, then replaces the second instance of ([0-9]) with itself (i.e. no change).
Update: Adrienne Montgomerie decided to test ChatGPT on creating a wildcard search for this. Here are her results: https://scieditor.ca/2023/03/editor-and-ai-wildcard-searches/
[…] is a solution Rhonda Bracey developed. Adding the closing bracket mostly avoids the problem she […]