Fascinated but Scared by Wildcards? Here’s How You Find Your Way In

So much of life is about who’s in your set. Word’s wildcards are really no different.

Most of us have a ‘crowd’ that we feel some sort of affinity with. Professional groups, special interests; type of food or music we like; and so on.

Well, wildcards are about your set, too. We don’t mean who’s in your set; we mean what’s in your setthe set of letters and numbers you’re looking for. And, as it happens, that all comes down to brackets—but these ones aren’t needlessly taxing. There are four kinds of brackets in Word wildcards: square, curly, angle, and parentheses (and if you’re the kind of stickler who insists that parentheses are not brackets, accept our apologies, but we’re set in our ways on this). Let’s have a look at why these are the heart and soul of wildcards.

Squaring It Off: []

Square brackets are the casting agency of wildcards: they let you pick which letters, digits, or other characters you want. For example, let’s say you’re trying to find all the instances of Mr., Ms., and Dr. in a document. Sure, you could do three separate searches, but why not do something a bit more elegant? You can see that each of those terms is a capital letter—either M or D—followed by a lower-case letter—either r or s—followed by a full stop. That means you can use brackets like this to find them:

[DM][rs].

That says “We’re casting for three letters here. The first one is D or M (capital letters only, please!). The second is r or s (lower-case!). The third is a period.” And when you type that into “Find” with “Use wildcards” checked, your search is the casting call: it will find all instances of Dr., Mr., and Ms. It will also—you may have noticed—find all instances of Ds. However, that will probably be zero, because what the heck is Ds.?

You can specify ranges, too. If you want to find a digit that’s 1, 2, 3, 4, or 5, you can put [1-5]. If you want to find any digit, you just put [0-9]. Any capital letter? [A-Z]. Any lower-case letter? [a-z]. And any letter at all, capital or lower-case? That’s [A-z], because in the mind of Word’s wildcards, capital letters come before lower-case ones.

Curling Up with a Few Friends: {}

What about if you want to have more than one character responding to your casting call? Let’s say you want to find Mr., Ms., or Mrs. (never mind the Dr. this time). You can specify the M and the period, but you want either one or both of r and s. How do you do that? You use the curly brackets. The number or numbers you put in curly brackets say how many of the previous casting call (square bracket set) you want. So if you want either one or two of the set r and s between M and a period, you put:

M[rs]{1,2}.

This will find Mr., Ms., and Mrs.—along with Mrr., Mss., and Msr., but those aren’t likely to come up unless you’re working on a transcription of cat speech.

You can see that two digits inside curly brackets mean at least as many as the first number, and no more than the second number. But wait—there’s more. Infinitely more, if you want. You can put in a comma and no second number and then you’ve specified a lower limit but no upper limit. So [A-z]{4,} will find all strings of letters (upper or lower-case) that are at least four letters long. So it will find heck and it will find Supercalifragilisticexpialidocious, and it will even find TelePrompTer. But it won’t find you (because that’s only three letters before you get to something that’s not a letter).

The bad news is you can’t say “no lower limit”; you have to specify at least one. There’s no way to say “zero or more of this set”—a pity if you want to find both (and only) JPEG and JPG, but consider what it would try to do if you specified just zero or more of a set without anything else next to it.

However, you can put just one digit to specify exactly how many. For instance, if you want a set of exactly three capital letters (to find all those three-letter initialisms), you specify [A-Z]{3}—you don’t need (and don’t want) to put [A-Z]{3,3}. But bear in mind that if it’s finding any set of three capital letters, if it sees something like CRUNCH it will find CRU, RUN, UNC, and NCH, in sequence (assuming you’re searching one at a time, not doing a replace-all—which seems like a frightening thing to do with a search this broad). So if you want to make sure you’re finding only sets that are three letters long and no longer, you need to try another angle…

Finding Your Angle: <>

Specifically, you need to try the angle brackets. These may look exactly like the “less than” and “greater than” signs, but that’s because they are. They’re the symbols you get by hitting shift and comma or period, respectively. And while the square brackets let you specify what and the curly brackets let you specify how many, the angle brackets let you specify where—as long as that “where” is the start or end of a word.

The cool thing about angle brackets is that they don’t need to travel together. You don’t have to specify a whole word! You can just say “find me a word that starts with x”—which you do by typing <x—and it will find you xenon, xanthan, xylophone, and so on (but not Xavier because that’s a capital X; you would need to search <[Xx] for that).

Well, OK, technically it will find just the first letter of those words. If you’re planning to find and replace every word that starts with x or X (don’t ask us why; the heart has its reasons), you’ll want to search for this:

<[Xx][A-z]{1,}>

Which means “find me a word that starts with an x, of any kind, followed by one or more other letters of any kind, right up to the end of the word.” This will not find you a name like XÆ12ok because that contains characters that aren’t in the set [A-z]. But if you’re looking for names like that, you may have bigger concerns.

You can also find just the end of a word, naturally. For instance, if you want to find all possessives—or, more precisely, all words that end in ’s or s’—you can search for this:

[’s]{2}>

But don’t forget that that will also find any contractions that end in ’s, because it has no idea whether Johnny’s home means “Johnny is home” or “the home belonging to Johnny.” It’s just a simple search! It will also find words that end in ss—and in ’’ if you have any. Also, make sure you use the correct curly apostrophe. If you type in ['s]{2}> with a straight apostrophe, it won’t find the curly ones, because those are not the same. Wildcards may be wild, but they are fussy. It will, however, look for both if you tell it to like this:

[’s ']{2}>

The Wildcard Minivan: ()

OK, so you’ve found your various variables. What if you want to move them around? What if you want to keep some of them, move some, and get rid of the others? It’s time to load your cast into minivans and drive them around. And by minivans, we mean parentheses.

This is where wildcards become especially powerful. Parentheses will not only let you find specific sets, they will let you move them around without changing them. Let’s say you have a list of names in this format:

  • Bogart, Humphrey.
  • Dietrich, Marlene.
  • Grable, Betty.
  • Lorre, Peter.

And let’s say you want to change them all to this format:

  • Humphrey Bogart
  • Marlene Dietrich
  • Betty Grable
  • Peter Lorre

In other words, you want to find a name (i.e., a word that is a capital letter followed by arbitrarily many lower-case letters), a comma and a space, another name, and a period, and you want to change it to the second name, a space, and the first name, and that’s all. What you do is put them in four minivans and swap the order of the two minivans that contain names, and drive the other two off a cliff leave out the other two. So you start by finding these four groups—using the parentheses to group them:

 

(You’ll notice that this doesn’t find names that have spaces, apostrophes, or periods in them. That is, as the maths textbooks say, left as an exercise for the reader.) Now, in your “Replace” box, you put this:

\3 \1

What that means is “the third group, a space, the first group”—and that’s it! You see, you specify the groups in the “Replace” box by using a backslash followed by a number indicating where in the sequence the group is. In this case there are four groups, so you could specify them as \1\2\3\4 if you wanted to replace them with themselves exactly unaltered, or with \3\2\1\4 if you wanted to swap the order of the names but leave the punctuation in place. (You may also have noticed that we could have grouped the comma and space separately and kept the space—so Find: (<[A-Z][a-z]{1,}>)(,)( )(<[A-Z][a-z]{1,}>)(.) and Replace: \4\3\1—but that’s less elegant, and if you can’t be elegant, what are you even doing with yourself?)

That’s Not the Whole Set

That’s not the whole set of Word wildcards—there are other characters, too:

  • ? means any one character
  • * means any number of any characters (use this carefully!)
  • @ means repeat the previous character or casting call any number of times
  • ! means “not the following character(s)—anything else, but not that!”
  • \ in the “Find” box means “treat this as a regular character, not a wildcard”

Making the Most of Wildcards

Once you get going with wildcards, you’ll find more and more uses for them. For instance, if you’re editing a document and you know that the author(s) are not always reliable in their use of e.g. and i.e.—using the wrong one, for instance, and sometimes leaving out the periods—you can specify this search as one of your checks:

<[.egi]{2,3}>

This will find all instances of ie, i.e, eg, e.g that have no letters before or after, plus of course all other instances of words consisting of two or three of that set, such as gig and egg—you can easily ignore those. It doesn’t find the closing period because wildcards don’t believe words can end with a period; a period is one of the things that can come after the end of a word. But since you’re applying your judgment to each instance one at a time, that’s not really a problem.

Getting Started

As long as you have Word, you already have wildcards; you just need to check “Use wildcards” in the Advanced Find and Replace.

For more help with wildcards, try the Wildcard Cookbook by Jack Lyon. Packed with detailed screenshots and instruction, it shows you how to get the most from wildcard search including real-world examples that you can simply copy and paste.

The paperback is usually around $10. However, you can get a PDF version absolutely free and you can download it here.

Check Your Text Faster with PerfectIt