Wildcard characters for searching in Word:
Wildcard | Meaning and Example using the wildcard |
---|---|
^13 | A 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 d onut”. 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”. |
\wildcard | Find the specified wildcard. \* finds the * character, \< finds the < character, \> finds the > character. |
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:
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.)
- Choose
Home > Replace
from theEditing
group (or pressCtrl+H
) to display theReplace
tab of the Find and Replace dialog box. Clear any formatting from the “Find what” box and the “Replace with” box by clickingNo Formatting
button. - Enter
(<*>) (<*>) (<*>)
in the “Find what” box, with a space between each closing parenthesis and the opening parenthesis following it. - 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.
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.