Using Wildcards–the Basics

Subscriber Allene Goforth (agoforth@aros.net) wrote:

"I use your 'Searching with Microsoft Word's Built-In Codes' list all the time, but Word's restrictions on what codes can be used in the 'Replace with' box are a pain. I'd love to see an issue of Editorium Update that deals with wildcard searching."

Thanks for the suggestion, Allene. Here goes:

When I was in the fifth grade in wintry Idaho, rather than venturing out into the cold, some fellow students and I often spent recess playing poker. (Did our teacher know about this? I can't remember.) Being *extremely* sophisticated players, we often designated jokers, deuces, *and* one-eyed jacks as wild cards--that is, they could represent any card in the deck. With the help of these wild cards, we had plenty of royal flushes, hands with five aces, and so on. Now that was poker!

Microsoft Word, too, has a bunch of "wild cards" (which Microsoft spells as one word) that you can use to find various combinations of characters in a document. Wildcards can get pretty complicated, but this week we'll cover just the basics.

The simplest wildcard is the question mark (?), which represents any single character. If you want to see how it works, try this:

1. Open a document with some text that you can play around with.

2. Click the "Edit" menu.

3. Click "Find."

4. In the "Find What" box, enter a question mark (?).

5. Put a checkmark in the "Use Pattern Matching" box. (You may need to click the "More" button first.) Checking this box tells Microsoft Word that you're going to use a wildcard. If you didn't check the box, Microsoft Word would assume you were trying to find a question mark.

6. Click the "Find" button.

Microsoft Word will find the first character after your cursor position. Click the "Find" button again. Microsoft Word will find the next character. And so on.

That doesn't seem very useful, but let's suppose you're editing a document that was scanned from a magazine article and is riddled with typos. You notice that the word "but" shows up in various ways, including "bat" and "bet." Let's say that this is a technical article with no references to baseball, winged mammals, or games of chance, so you decide to use the ? wildcard to find "bat" and "bet" and replace them in a single pass. Here's the procedure:

1. Click the "Edit" menu.

2. Click "Replace."

3. Enter "b?t" in the "Find What" box.

4. Enter "but" in the "Replace With" box.

5. Put a checkmark in the "Use Pattern Matching Box."

6. Click the "Replace All" button.

Both "bat" and "bet" will be replaced with "but." The problem is, so will "bit." And, unfortunately, since you can't specify "Find Whole Words Only" when the "Use Pattern Matching" box is checked, Microsoft Word will replace "better" with "butter," "combat" with "combut," and who knows what else. So, instead of clicking the "Replace All" button, you should click the "Replace" button for each individual item as needed.

Now you begin to see the power--and the danger--of using wildcards. Like cutthroat poker, they are not for the faint of heart. But if you know what you're doing, they can be very useful. Unfortunately, they won't help much in the "Replace With" box. In fact, you can't use them there at all. Why? Because Word has no way of knowing what you want them to represent.

Let's say you want to find "but" and replace it with either "bet" or "bat," so you put "b?t" in the "Replace With" box and click the "Replace All" button. Word doesn't know whether you want to replace "but" with "bet" or "bat," so it just replaces it with the actual text "b?t." So, basically, the only thing you can use in the "Replace With" box is actual text or certain built-in codes, mentioned earlier. You can get the list of codes here:

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

Next week I'll explain wildcard searching in more depth. Until then, here's a list of wildcards for you to play with (on some junk text--don't use a real document):

? Finds any single character:

"c?t" finds "cat," "cut," and "cot."

* Finds any string of characters:

"b*d" finds "bad," "bread," and "bewildered."

[ ] Finds *one* of the specified characters:

"b[ai]t" finds "bat" and "bit" but not "bet."

[-] Finds any single character in the specified range (which must be in ascending order):

"[l-r]ight" finds "light," "might," "night," and "right" (and "oight," "pight," and "qight," if they exist).

[!] Finds any single character *except* those specified:

"m[!u]st" finds "mist" and "most" but not "must."

"t[!ou]ck" finds "tack" and "tick" but not "tock" or "tuck."

[!x-z] Finds any single character *except* those in the specified range:

"t[!a-m]ck" finds "tock" and "tuck" but not "tack" or "tick."

{n} Finds *exactly* n occurrences of the previous character or expression:

"re{2}d" finds "reed" but not "red."

{n,} Finds *at least* n occurrences of the previous character or expression:

"re{1,}d" finds "red" and "reed."

{n,m} Finds from n to m occurrences of the previous character or expression:

"10{1,3}" finds "10," "100," and "1000."

@ Finds one or more occurrences of the previous character or expression:

"me@t" finds "met" and "meet."

< Finds the beginning of a word:

"

Finds the end of a word:

"in>" finds "in" and "main" but not "inspiring."

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!