Word: Replace ‘to’ in a number range with a dash

March 26, 2023

Pam 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:

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click More.
  3. Select the Use wildcards checkbox.
  4. In the Find, type: ([0-9])( to )([0-9]) 
    (NOTE: There is a single space either side of the ‘to’)
  5. 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.)
  6. 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/

One comment

  1. […] is a solution Rhonda Bracey developed. Adding the closing bracket mostly avoids the problem she […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: