Categories
Microsoft Word

Wildcard characters for searching

The wildcards characters, ?-*!<>@()[]{}, helps you to find character patterns in the text instead of specific character sequences. Wildcard searches are always case sensitive, meaning that upper and lowercase letters differ. They are often used to perform complex search-and-replace operations, and to validate that text data is well-formed.

Wildcard characters for searching in Word:

WildcardMeaning and Example using the wildcard
^13A paragraph mark (like ^p in regular search)
?Any “one” character. sh?p finds “ship” and “shop”.
*A string of characters (including spaces). w*d finds strings of text that start with “w” and end with “d”, such as “wad”, “wood”, “wicked”, and part of “strawberry donut”. This also finds “wd”, because the string can have zero length.
<The beginning of a word or group of characters. <wear finds “wear”, “wearisome”, and other words with “wear” at the beginning, but not “swear” or “sportswear”.
>The end of a word or group of characters. >ble finds “horrible”, “terrible”, and other words that end in “ble”, but not words such as “bleary” or “ablest”.
( )Group and capture wildcard characters. (<*>) finds a word by specifying a group with the start of the word, the * wildcard to find a string of characters, and the end of the word.
[ ]One or more of the characters specified. w[aeu]d finds “wad”, “wed”, and “weed”, but not “wood”, because “o” is not included in the bracketed selection of letters.
[a-f]One of the characters in the specified range. [l-r]ower finds “lower”, “mower”, “power”, and “rower”, but not words such as “tower” or “cower”, which are outside the range. You must specify the range in alphabetical order.
[!a-f]Any character except those in the specified range. [!l-r]ower finds “bower”, “cower”, “dower”, “tower”, and “vower”, but not words such as “lower” or “mower”, which are inside the range. Again, you must specify the range in alphabetical order.
{n,}n or more instances of the previous character or expression. ke{1,}p finds “keep”, “kepi”, and “kept”.
{n,m}From n to m instances of the previous character or expression, where m is 255 or less. 5{1,3} finds “5”, “55,” and “555”.
@One or more instances of the previous character or expression. pe@p finds “pep” and “peep”.
\wildcardFind the specified wildcard. \* finds the * character, \< finds the < character, \> finds the > character.
Wildcard characters for searching in Word

You’re not going to remember these wildcards, are you? No matter. Check the “Use wildcards” box in the Find and Replace dialog box, and you can click the Special button to display a pop-up menu of the wildcards:

Check Use wildcards box and click the Special button to display wildcards

Grouping and Capturing

Parentheses ( ) perform two functions: grouping and capturing. Text matched by the subpattern within parentheses is captured for later use. Capturing parentheses are numbered by counting their opening parentheses from the left. If backreferences are available, the submatch can be referred to later in the same match with \1, \2, etc. The captured text is made available after a match by implementation-specific methods. For example, (<*>) \1 matches duplicate words, such as: word word, this this, etc.

Use grouping and capturing to change “Firstname Lastname” to “Lastname, Firstname”

Let’s change the “FirstName LastName IdNum” to “IdNum Tab LastName, FirstName.”

Open the document and select the part of it that contains the names. (If the whole document is the names, you don’t need to select anything. Otherwise, select only the names, as the pattern matches any sequence of three words.)

  1. Choose Home > Replace from the Editing group (or press Ctrl+H) to display the Replace tab of the Find and Replace dialog box. Clear any formatting from the “Find what” box and the “Replace with” box by clicking No Formatting button.
  2. Enter (<*>) (<*>) (<*>) in the “Find what” box, with a space between each closing parenthesis and the opening parenthesis following it.
  3. Enter \3^t\2, \1 in the “Replace with” box, including the space after the comma. Check the “Use wildcards” box and click the Replace All button. Word changes the position of the words.
Using parentheses to group and capture words to change their order

How does this work? You’ve just used three wildcard characters to build a regular expression. Once you check the “Use wildcards” box in the Find and Replace dialog box, you can use the wildcard characters shown in the above Table to search for items.