Why Your Word Wildcard Search Went Wrong: Pitfalls and Hard Limits

Wildcards are powerful, time-saving and, dare we say, a little bit fun. But this is a post about why a Word wildcard search can let you down.

Not to put you off. Actually, the opposite: almost every wildcard disaster comes from one of a small number of predictable causes, and knowing them in advance turns “why has it done that?!” into “ah, of course, that’s why.” There are also four genuine, non-negotiable limits in Word that no amount of cleverness will get you past. It saves a great deal of time to know where the wall is before you run into it.

 

Word wildcard search pitfalls: false positives and how they multiply

A false positive is a hit that fits your pattern perfectly but that you didn't want.

Say you want every four-digit year. [0-9]{4} also grabs chunks of phone numbers, so you add word boundaries: <[0-9]{4}>. Better, but that still catches 4217 in ISO 4217. So, you narrow it: years start with 1 or 2, giving <[12][0-9]{3}>. Except now you'll catch 1000, which could be a year or a number with its thousands separator missing. You can narrow the pattern further: <[12][1-9][0-9]{2}>.

You can see the string getting more baroque with every objection, and this is the real lesson. There's a point where a search is probably fine but not definitely fine, and only you can decide when you've reached it. The answer is rarely a perfect string. It's usually a good string plus a careful look at the hits.

 

Asterisk misery

The asterisk matches zero or more characters, and “more” can mean hundreds, while “characters” includes spaces and paragraph marks. Search for be*st and you’ll get best and bedpost, but also beauty therapist and bed and breakfast, because nothing tells the asterisk to stop at the end of a word. Or a sentence. Or a paragraph.

If you're reaching for the asterisk, there's usually a tighter way to say what you mean.

 

URLs will ruin your day

A URL can contain all sorts of characters, in almost any order, and some of them will match the elegant pattern you’ve built for ordinary language. There’s no real defence except knowing they’re there.

Which is, as it happens, one of the few jobs the asterisk is perfect for. Every URL has one property in common: no spaces. So let the asterisk run and stop it with a space.

www*[ ^13^t]

http*[ ^13^t]

Or condense both into one:

<[htw]{3}*[ ^13^t]

You'll pick up the occasional thwack and thwart, but as a way of checking whether a document contains URLs at all, before you start doing anything ambitious, it works well.

 

Turn Track Changes off

This one is short and absolute. Running a wildcard replacement with Track Changes enabled can produce results that look impossible, including elements in the wrong order and punctuation appearing where nothing asked for it. The precise cause is not always clear, but the reason matters less than the rule.

Remember, wildcards and tracking? Send one packing. (T-shirt slogan, perhaps?)

 

@ versus {1,}

Both mean “one or more of the previous thing.” They look interchangeable, and often are. But the difference can still cost you an afternoon.

In theory, @ and {1,} are equivalent: both mean one or more occurrences of the preceding character or expression. In practice, Word can behave differently depending on the rest of the search string, and one version may work when the other does not. If a search fails despite looking right, try swapping {1,} for @, or vice versa, then check the matches carefully.

The main practical difference is flexibility: {1,} can be adjusted to specify a minimum or maximum number of repetitions, while @ is shorthand for one or more. Whichever you use, test the search against representative text.

 

The four hard limits

There are certain limitations that can't be resolved, points at which Word can go only so far, with no clever way of getting around them. These aren't traps. They're walls.

  1. Seven sets of square brackets. That's your lot. Seven inventories of [a-z] already give Word more than eight billion combinations to consider, so the ceiling is understandable, but it's absolute.
    If you need an eighth, you're running two searches. This is worth planning for. A broad four-digit pattern, <[0-9]{4}>, is loose; <[12][1-9][0-9]{2}> is more selective, but excludes numbers beginning with 10 or 20. If your surrounding context keeps the broader version safe, use it and free up bracket sets for something that needs them.


  2. Nine expressions. You can’t create more than nine sets of parentheses for recall. This is also why \10 in a Replace field unambiguously means “expression 1, followed by a zero”; there is no tenth expression for it to be confused with.


  3. No optional item. This is the big one, and the one you’ll curse most often. You can’t say “zero or one of this specific thing.” The asterisk can match zero characters, but it can also match any number of any characters, which is far too broad; the question mark matches exactly one character of any kind, which is rarely what you want. Occasionally, you can work around this by widening a search to “one or two”: datu[ms]{1,2} catches both datum and datums and turns both into data. That works only because datus and datusm aren’t words. Apply the trick carelessly, and you’ll create false positives rather than avoid them.


  4. No lookup tables. Word can't swap items from one list for their equivalents in another. It won't turn Roman numerals into Arabic ones or currency codes into currency symbols, because it has no way of knowing which pairs with which. You can find them all in one go, but the replacement has to be specified one at a time.


Knowing the walls makes you faster

None of this should stop you from using wildcards.

Most searches work the first time, and the ones that don't usually fail for a reason mentioned in this article. Recognizing which one you've hit is most of the battle. When a string won't run at all, Word's error messages narrow it down further.

Brave New Word is our free ebook on Wildcard Find & Replace in Word and PerfectIt. It explains the limits you may come up against and includes the complete symbol set, dozens of worked examples across medical, legal, technical, proposal, and academic writing, a full troubleshooting chapter on every error message Word throws and what it means, plus the usual suspects behind a search that finds nothing. There are also two chapters on building wildcard checks into PerfectIt and a printable cheat sheet at the back. 

Previous
Previous

Word Wildcard Error Messages, Translated

Next
Next

How to Use the Wildcard Find & Replace Check in PerfectIt