How to specify single- and double-digit values using the Replace feature in Word

Any time a Microsoft Word’s Find & Replace task goes beyond literal values, you might need wildcards. Susan Harkins will show you how to use these handy devices.

Image: prima91/Adobe Stock

Most of us learn how to use Microsoft Word’s Find & Replace feature early on because it’s so easy and helpful. However, sometimes a task is complex enough to send us back to the drawing board. For example, you might think replacing numbers comprised of only one or two digits impossible, but it isn’t. Thanks to a few wildcards, you can accomplish this in only one run. In this article, I’ll show you the wildcard string that will find all numbers consisting of only one or two digits.

SEE: Software Installation Policy (TechRepublic)

I’m using Microsoft 365 on a Windows 10 64-bit system, but you can use an earlier version. I recommend that you hold off on upgrading to Windows 11 until all the kinks are worked out. For your convenience, you can download the demonstration .docx  file. However, it’s a simple list of one-, two- and three-digit numbers that you can easily create yourself.

The Replace string

Let’s keep the Replace string simple. Specifically, let’s add text to the beginning and the end of each number. Doing so lets us see where things work and don’t work. We’ll be working with a simple set of numbers, shown in Figure A. The simple list contains single-, double- and triple-digit numbers.

Figure A

We’ll use this list of simple numbers in Word to test several find strings.

We want to ignore any number comprised of more than two digits. To that end, we’ll work with the following replace string:

pre^&sub

If Word finds the number 03, this Replace string will return pre03sub.

How to find numerical digits

To replace or modify existing numerical values comprised only of one or two digits, you need wildcards. You could consider simplifying the task by running two different replace tasks: one that finds only single-digit numbers and one that finds only double-digit numbers. Fortunately, you can easily combine both searches into one.

The first wildcard component we’ll try is [0-9], which finds any digit.

Now, let’s work through the first Find string:

  1. On the Home tab, click the Editing option and click Replace. Or press Ctrl + h.
  2. In the resulting dialog, enter [0-9] as the Find What string.
  3. Enter pre^&sub as the Replace With string.
  4. If necessary, click More.
  5. Check the Use Wildcards option shown in Figure B.
  6. Click Replace All and then OK to close the information prompt.

Figure B

Click Use Wildcards in Word.
Click Use Wildcards in Word.

As you can see in Figure C, this Replace task added the Replace With string to every digit, not every number. That means we need a wildcard that matches a single word. In this case, word includes numbers. If you’re working with the demonstration file, be sure to press Ctrl+Z to undo the changes made by running Replace before you continue to the next wildcard example.

Figure C

The Word Find string needs a bit of work.
The Word Find string needs a bit of work.

Fortunately, there is a wildcard that can handle this particular find requirement: <>. By enclosing the [0-9] string in <> characters, Word will interpret combined digits as a whole word. Let’s add the <> characters and try again.

  1. Press Ctrl + H.
  2. The Replace feature remembers the last task, so you don’t have to enter the strings from scratch. Instead, insert the < and > characters, as shown in Figure D.
  3. Click Replace All and OK.

As you can see in Figure D, we’re a bit closer. Word ignores the three-digit numbers, but it also ignores the double-digit numbers. Don’t forget to press Ctrl + Z to undo the changes before you continue.

Figure D

Word ignores digits with more than on digit.
Word ignores digits with more than one digit.

We need a way to specify double-digit numbers while ignoring numbers with more than two digits. That’s where the next wildcard comes in: {}. This wildcard specifies any sequences of digits, which you specify. {1,} would find single-digit numbers; {1,2} will find only single- and double-digit numbers. Let’s add it to our existing Find What string and see what happens:

  1. Press Ctrl + H.
  2. Tack the {1,2} wildcard component to the end of the Find What string, as shown in Figure E.
  3. Press Replace All and then OK.

Figure E

Finally, the Find What string works.
Finally, the Find What string works.

Success! This Find What string meets every requirement. Let’s review the wildcards we used and what they do.

A quick review of wildcards in Word

Let’s take a minute to review what each wildcard does:

  • [0-9] specifies all digits. If you used [0-3], Word would find only the digits 0 through 3.
  • <> limits the search to single words. Subsequently, <[0-9]> won’t treat numbers consisting of more than one digit as a bunch of individual digits.
  • {} lets you specify a sequence of digits; {1,2} will find numbers that consist only of one or two digits.

By combining these three wildcards, <[0-9]{1,2}> you’ll find only numerical values that consist of one or two digits. Once you know how the wildcards work, it’s easy to come up with this string so you can run only one Replace task.

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! TechNewsBoy.com is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.