Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Replacing Spaces in Part Numbers with Dashes.

Replacing Spaces in Part Numbers with Dashes

Written by Allen Wyatt (last updated October 22, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Terry has a document that contains a lot of numeric data. Often, the document has part numbers with spaces in them, such as "422 891A." Terry needs a way to search through the document and find any "digit-space-digit" sequence and replace it with "digit-dash-digit." For instance, "422 891A" would be changed to "422-891A." Terry wonders if there is a way to do this with Find and Replace.

This type of find-and-replace operation can be done quite easily by using the wildcard searching built into Word. Here's the quick version:

  1. Press Ctrl+H to display the Replace tab of the Find and Replace dialog box.
  2. Click on the More button if it is available.
  3. Select the Use Wildcards check box.
  4. In the Find What box enter "([0-9]) ([0-9])", without the quote marks and with a single space in the middle.
  5. In the Replace With box enter "\1-\2", again without the quote marks.
  6. Click on the Replace All button.

That's it. When the Use Wildcards check box is selected (in step 3), Word allows you to use patterns in the search. In this case, each instance of [0-9] means "match any single digit in the range of 0 through 9." The parentheses around each instance is for grouping purposes that allows what is found within that group to be referenced in the Replace With box. So, essentially, the Find What pattern matches any single digit followed by a space followed by any single digit.

What is then entered in the Replace With box is a set of references to what was found. The \1 and \2 indicators mean "what was found in the first set of parentheses and what was found in the second set of parentheses." So, this means "replace the first digit with itself, followed by a dash, then replace the second digit with itself."

Of course, you may need to get even more specific in the pattern you search for, if it is possible that the digit-space-digit pattern may appear in other places in the document and you don't want them affected. In that case, perhaps your part-number pattern consists of three digits followed by a space and then three more digits and then a single alphabetic character, as shown in the example provided at the first of this tip. If that is the case, then you can search for the following in step 4:

([0-9]{3}) ([0-9]{3})([A-Z])

In this case, you'll immediately note the addition of two instances of {3}. These characters are an indicator that there needs to be three of whatever immediately precedes the indicator. Thus, there needs to be three digits, each of 0 through 9. Also, the [A-Z] characters matches a single capital letter in the range of A through Z.

Also note that there are three sets of parentheses in this Find What pattern. These then can be referenced in the Replace With box (step 5), as follows:

\1-\2\3

Since this search is more specific, there is very little chance that you will replace spaces with dashes where you didn't mean to do a replacement.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10835) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Replacing Spaces in Part Numbers with Dashes.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Removing Protection from a Protected Workbook

Excel provides built-in capabilities to protect your workbook files. If you apply these capabilities, it is possible that ...

Discover More

Getting a Double-Spaced Printout

When working with printed documents, many people prefer to see the document double-spaced. If you have a single-spaced ...

Discover More

Calculating an Average within a Date Range

Need to find an average of the values that fall within a date range? Excel provides a number of ways you can do this, ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Using Optional Hyphens

Adding hyphens to your document can affect the way in which Word wraps text from one line to the next. Optional hyphens, ...

Discover More

Controlling Overtype Mode

Some people like to have Word replace previous information as they type; this is called 'overtype mode.' You can control ...

Discover More

Deleting Freezes Computer

Sometimes a strange object or text may appear in your document, as happened to Sharon. To complicate the situation, her ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.