Wildcard Grouping

For the past few weeks we've been talking about using wildcards to find and replace text in Microsoft Word. This week we'll discuss wildcard grouping, which is simply a way of telling Word that you want certain wildcards to be used together as a unit.

Continuing with our example from last week, let's say that you're editing a document with lots of numbered lists, like this:

1. Lorem ipsum dolor sit amet.

2. Ut wisi enim ad minim veniam.

3. Duis autem vel eum iriure dolor.

Now let's say that you want to replace the space after each number and period with a tab. After calling up the Replace dialog (Edit > Replace) and putting a check in the "Use wildcards" or "Use Pattern Matching" box, you could enter the following string of characters into the "Find What" box:

^013[0-9]@.

(You can't see it, but there's a space on the end of that string, and it needs to be included.) As you probably recall from the past few weeks, this tells Microsoft Word to do the following:

1. Find a paragraph mark (^013)

2. followed by a number ([0-9])

3. followed by one or more numbers (@)

4. followed by a period (.)

5. followed by a space ( ).

But that still won't let us replace that space with a tab. Why? Because there's no way to replace the space independently of the rest of the string--whatever the string finds *includes* the space.

So let's try this:

(^013[0-9]@.)( )

Notice that we've grouped the wildcards and other characters together with parentheses. (In case you can't tell, that's our uncooperative space between the last two parentheses.) Such groups, for reasons known only to the mathematically minded, are called "expressions," and in this case there are two of them:

1. (^013[0-9]@.)

2. ( )

Grouping things together like this makes it possible to refer to each group independently in the "Replace With" box--a wonderful thing! So in the "Replace With" box, we'll enter this string:

1^t

That "1" is an example of the little-known "Find What Expression" wildcard, which lives deep in the wilds of Redmond, Washington, and only comes out at night. It's a backslash followed by the number one, and it tells Word to replace whatever is found by the first expression--

(^013[0-9]@.)

--with whatever the first expression finds. (Yes, you read that correctly.) In other words, Word replaces whatever the first expression finds with *itself.* That seems strange, but it means we can treat the second expression--

( )

--as an independent unit, which is exactly what we need to do. (By the way, "Find What Expression" wildcards are the only wildcards that can be used in the "Replace With" box. They are simply a backslash followed by a number.)

The ^t, of course, is the code for a tab, as explained in the November 14, 2000, issue of Editorium Update:

http://www.topica.com/lists/editorium/read/message.html?mid=1703968584

You'll notice that we haven't included a "2" code, which would replace something with whatever is found by our *second* expression, the space in the parentheses. Since we haven't included that code, the space will be replaced by nothing--in other words, it will be *deleted* during the Find and Replace. So the relationship between the wildcards in the "Find What" string and the "Replace With" string is something like this:

FIND WHAT: REPLACE WITH:

(^013[0-9]@.) > 1 (followed by a tab: ^t)

( ) > [nothing]

Now let's try using them:

1. Start the Replace dialog (Edit > Replace).

2. Put a check in the "Use wildcards" or "Use Pattern Matching" box (you may need to click the "More" button before this is available).

3. In the "Find What" box, enter this:

(^013[0-9]@.)( )

4. In the "Replace With" box, enter this:

1^t

5. Click the "Replace All" button.

Presto! All of the spaces after your numbers will be replaced with tabs, and your list will now look like this:

1.Lorem ipsum dolor sit amet.

2.Ut wisi enim ad minim veniam.

3.Duis autem vel eum iriure dolor.

To me, this is like magic, and it comes in handy more often than you might think. I hope you'll find it useful! In the future, I'll try to provide other examples that you can apply in your day-to-day work. Next week I'll show you how to use "Find What Expression" codes to move things around.

_________________________________________

READERS WRITE

After reading our past few newsletters on wildcard searching, a subscriber wrote, "Use Pattern Matching does not appear to be an option in my Word program."

I apologize for not explaining this. In Microsoft Word 6 and 95, "Use Pattern Matching" is an option in the Find and Replace dialogs, and selecting this option tells Word that you're going to use wildcards. In Word 97 and later, this option is simply called "Use Wildcards." To see this option, you may need to click the "More" button in the Find and Replace dialogs.

This entry was posted in Editing. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

You must be logged in to post a comment.

  • The Fine Print

    Thanks for reading Editorium Update (ISSN 1534-1283), published by:

    The EDITORIUM, LLC
    http://www.editorium.com

    Articles © on date of publication by the Editorium. All rights reserved. Editorium Update and Editorium are trademarks of the Editorium.

    You may forward copies of Editorium Update to others (but not charge for it) and print or store it for your personal use. Any other broadcast, publication, retransmission, copying, or storage, without written permission from the Editorium, is strictly prohibited. If you’re interested in reprinting one of our articles, please send an email message to editor@editorium.com

    Editorium Update is provided for informational purposes only and without a warranty of any kind, either express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, and freedom from infringement. The user (you) assumes the entire risk as to the accuracy and use of this document.

    The Editorium is not affiliated with Microsoft Corporation or any other entity.

    We do not sell, rent, or give our subscriber list to anyone. Period.

    If you’d like to subscribe, please enter your name and email address below. We publish the newsletter once a week, and on rare occasions we may send an important announcement. We never, ever send spam. Thank you for signing up!