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 Two Tabs with a Space in Limited Situations.
Written by Allen Wyatt (last updated March 25, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021
Terry often imports information, such as customer names, into Word from a different program. The problem is that the names are in the format (John^t^tDoe), where the first and last names are separated by two tabs and the entire name is surround by parentheses. Terry needs to replace the two tabs with a single space. He knows he could use a regular Find and Replace to do it, but it would affect all other instances of two tabs in the document. He wonders if there is a way to search for the parentheses, a word, and two tabs and replace it with the parentheses, the word, and a single space.
This can actually be done using the regular Find and Replace feature of Word. First, if the names are all within a single portion of your document, you could select the paragraphs that contain the names and do a simple Find and Replace to change the two tab characters to a single space. This would limit the replacements to just what you selected and avoid making changes in other parts of the document where there may be double tab characters used in a different context.
If this cannot be done (perhaps the names aren't limited to a single area of the document), then you can still use Find and Replace. All you need to do is do what is called a wild card search, which opens up the real power behind Find and Replace. Follow these steps:
Figure 1. The Replace tab of the Find and Replace dialog box.
The key to understanding what is happening with these steps is understanding the search pattern created in step 4. It is easiest to break it down into parts, with each part surrounded (in the pattern) by parentheses. The first part is this:
(\([A-Z][a-z]{1,})
This part says "find any opening parenthesis, indicated by \(, followed by a single uppercase letter, indicated by [A-Z], followed by at least one lowercase letter, indicated by [a-z]{1,}". The purpose of this part of the pattern is to find the first part of the name within parentheses, before the two tab characters. In Terry's original question, this would find the characters "(John".
The next part of the pattern is this:
(^t^t)
This part says "find two tab characters". This is fairly self-explanatory. Because this part follows the first part, just discussed, it means that the two tabs must follow the first name, as already mentioned. The third part of the pattern is this:
([A-Z][a-z]{1,}\))
This part of the pattern is very similar to the first part. It essentially says "find a single uppercase letter, indicated by [A-Z], followed by at least one lowercase letter, indicated by [a-z]{1,}, followed by a closing parenthesis, indicated by \)". Taken all together, the effect of the search pattern is to find the first name, followed by two tab characters, followed by the last name.
Remember that each part of the search pattern is encased within a set of parentheses. This allows each part to be referenced within the "Replace With" pattern in step 5. The pattern—\1 \3—means that whatever matches the search pattern is replaced with what was found in part 1 of the search pattern (the first name and leading parenthesis), a single space, and what was found in part 3 of the search pattern (the last name and trailing parenthesis). Very powerful, indeed.
You should be aware that you might need to modify what you search for, depending on the characteristics of the names in your document. As shown here, the search works great, provided that the names (first and last) begin with a single uppercase letter and have no other characters in them, such as spaces or periods. If your names aren't structured in this way, you can modify the search pattern to be less restrictive. For example, consider the following search pattern which could be used in step 4:
(\(*)(^t^t)(*\))
This finds any number of characters between the opening parenthesis and the tabs and any number of characters between the tabs and the closing parenthesis.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (5989) 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 Two Tabs with a Space in Limited Situations.
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!
The Find and Replace feature in Word is very powerful. So powerful, in fact, that you can change the formatting on ...
Discover MorePattern matching is a type of searching you can do in Word that is very powerful. Despite its power, it remains rather ...
Discover MoreThe most powerful search engine in Word uses pattern matching, but the way you specify special characters in a ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments