A walk on the wildcard side

In my experience, most editors – let alone less proficient users of Word – have little to no familiarity with Word’s wild cards and are afraid to try them. This is a pity: It’s like being afraid to learn how to copy and paste instead of retyping every time. Using wildcards is not hard, and it can save you a lot of time.

Do you need to memorize a whole bunch of rules? No. This isn’t a course where you will have a closed-book test at the end. Whenever you can’t think of what to do, the Microsoft Word MVP Site has a lovely resource at word.mvps.org/faqs/general/UsingWildcards.htm . You can just look there and refresh your memory. But I’ll save you a little time and effort with a rundown of the basic principles, followed by some useful examples.

Basic principle 1: Know your superheroes

There are a few symbols that, when you have “Use wildcards” checked under Find and Replace, become something magical and highly powerful:

  • *: The asterisk can represent any number of whatever characters. If you search w*rd you will find word, weird, walked backward, and even phrases such as what! To do 7 isn’t hard – anything that starts with a w and ends with rd and doesn’t have another w or rd in between. Also wrd, because * can stand for nothing at all.
  • ?: The question mark represents one character of any type. Search l??t and you will find lent, last, l33t, etc., but not lit or least.
  • @: The at-sign represents a repeat of the previous character zero or more times. If you search ah@ you will find ah, ahh, ahhh, etc.

Basic principle 2: Be more specific

Much of the time, you don’t actually want to use such high-powered ammunition. You may not be able to specify an exact word – if you could, you probably wouldn’t need wild cards – but you can limit it to a smaller set of characters. There are four tools you need for this:

  • <>: The angle brackets indicate the start and end of a word. So <*> is a word of any length, <?> is a one-letter word, and so on. You don’t have to use them together: ?> will find the last letter of any word.
  • []: Square brackets let you search for any one of a specified set of characters. If you want to find mad, bad, sad, or dad, you can search [bdms]ad. If you want to find a semicolon or colon, use [;:]. If you want any of a range of characters, you can use a hyphen to indicate the range: [0-9] means any numeral; [A-Z] means any capital letter; [a-z] any small letter; [A-z] any letter at all; [0-9A-z] will find any numeral or letter.
  • !: The exclamation mark means “not!” So if you want an occurrence of a letter other than lowercase p or q, for instance, use [!pq]. And if you want to find all words that are not capitalized, you can use <[!A-Z]*>.
  • {}: If you want more than one occurrence of the type of character just specified, you can specify how many using curly brackets. [0-9]{2} will find any two numerals: 29, 47, 68, etc. You can indicate minimum and maximum numbers of occurrences with a comma: [A-Z]{1,3} will find anything with one to three capital letters in a row; [0-9]{2,} will find any set of two or more numerals in a row (no upper limit). To find all capitalized words four or more letters long, use <[A-Z][a-z]{3,}> (if you don’t use the <>, you will also find the Phone in iPhone, for instance).

Basic principle 3: Divide and number

You are very likely to want to break down what you’re searching for into two or more parts, so you can change, move, or remove one part and not another. The way to do this is to use parentheses in your search term and backslash numbers in your replace term.

For instance, let’s say you have 99039 J Wilkins, 85042 K Palmer, etc., and you want it to be Wilkins: 99039, Palmer: 85042, and so on.

So you start with three parts: The number, the initial, and the last name. They are, respectively, [0-9]{5}, [A-Z], and <[A-Z][a-z]{1,}> – plus the spaces, don’t forget that there are spaces between the words. We can use parentheses to divide it into the following parts: ([0-9]{5})( [A-Z] )(<[A-Z][a-z]{1,}>).

We now have parts 1, 2, and 3. And that is how Word will know them – to be precise, as \1, \2, and \3. In your replacement, you are putting the third one first, then a colon and space, then the first one third – in other words, \3: \1. That’s it!

Basic principle number 4: Backslash your way out of conflicts

What if you want to find one of the special characters above as itself? What if you’re looking for parentheses, for instance? Just use a backslash before the character: \( and \) for the parentheses, \@ for the at-sign, and so on.

Now here are three examples of ways wildcard find-and-replaces can make your life easier.

Example 1: Putting en-dashes in number ranges

You want to change hyphens to en-dashes between numbers? You just need to find any number, hyphen, any number, and change it to the same but with a dash in place of a hyphen:

Find: ([0-9])(-)([0-9]) Note that you don’t have to backslash the hyphen – it only has special meaning inside square brackets.

Replace: \1–\3

Be careful, though – if you have phone numbers in your document, you will need to avoid them or change them back.

Example 2: Converting US-style large numbers to metric-style

How about if you need to change numbers such as 4,231 to 4231, but numbers such as 67,853 to 67 853? First change the 5- or 6-digit numbers (because the 4-digit numbers also occur inside the 5- and 6-digit ones):

Find: ([0-9]{2,3})(,)([0-9]{3})

Replace: \1 \3

Then change the four-digit numbers:

Find: ([0-9])(,)([0-9]{3})

Replace: \1\3

But beware: if you have numbers over a million, they will be affected by this, so you’ll have to deal with them first.

Example 3: Formatting titles in a bibliography

Let’s say your bibliography entries are like this:

Garfield TC. The mechanisms of purring. Journal of Feline Biomechanics 23:7 (1998): 12–45.

And you want them to be like this:

Garfield TC. “The mechanisms of purring.” Journal of Feline Biomechanics 23:7 (1998): 12–45.

Because you can’t apply formatting to just part of the result, you need a multi-step process. First add the quotes and some markers for where the italics will start and stop (I’ll use | and §, assuming those are used nowhere else in the text to be dealt with). Turn off the automatic smart quotes – Word may curl them the wrong way.

Find: ([A-Z]. )([A-Z]*.)( )([A-Z]*)( [0-9])

Replace: \1"\2"\3|\4§\5

Then let’s italicize the title:

Find: (|)(*)(§)

Replace: \2 Specify format as italic

Then you need to turn on autocorrect to smart quotes and find and replace all the quotes (find " and replace with " and it will curl them all for you). Et voilà: like magic!

8 responses to “A walk on the wildcard side

  1. Excellent article, thanks. I’ve bookmarked it for future reference and added your blog to my reader.

  2. It would have been helpful if this article had a subtitle, or explained in the first paragraph, what it is about: advanced search and replace functions.

  3. Pingback: Master Word’s Find and Replace Function with Wildcards and Codes » Right Angels and Polo Bears

  4. Pingback: Tech Tools for Writers

  5. Pingback: A Self-Editing Toolkit | Tech Tools for Writers

  6. I can’t get the square brackets one to work for me. In fact, anything in their screenshot of the “special” list in “find” between “Character in Range” and
    “0 or more characters” isn’t there for me to use. (I use Word 2010, business.)

  7. Pingback: Why Editors Use Word—Writers can Harness Word’s Powers, too! | Tech Tools for Writers

  8. That’s a great article!! I have been searching for this a long time already. There is still one thing I’m searching for: do you maybe know of any possibility to find/replace font types such as bold, italic, or underlined text without using the formatting option in the find/replace field but using a wildcard instead? I am searching for this, as I’m using a word macro that replaces a complete list (saved in a separate word file) where I cannot apply the formatting option one can use in the normal find/replace field of word.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s