Wednesday, February 27, 2019

Using Word's Wildcard Search Option

The search feature in Microsoft Word is very powerful. As well as standard string searches, you can use wildcard characters and regular expressions to perform complex searches and
replacements. For a detailed explanation of wildcard searches in Word, with many examples, see Wildcard Cookbook for Microsoft Word by Jack Lyon. Examples below are from that book.

To enable wildcard searches in Word:

  1. Open the Find and Replace dialog box. From the Find drop down menu in the Home tab of the ribbon, choose Advanced Find or press CONTROL+H.
  2. In the Find and Replace dialog box, click More. The Search Options pane opens.
  3. Select the Use wildcards check box. Note that this check box also enables the use of regular expressions in searches and replacements.

Basic wildcard searches use the ? and * characters.

  • ? finds any single character: “b?t” finds “bat”, “but”, and “bet”.
  • * finds any string of characters: “b*d” finds “bad”, “bead”, and “beard”.

More complex searches and replacements are possible using regular expressions with the following wildcard characters:

  • [ ] finds one of the specified characters: “b[ai]t” finds “bat” and “bit” but not “bet”.
  • [-] finds any single character in the specified range (which must be in ascending order): “[l-r]ight” finds “light”, “might”, “night”, and “right” (and “oight”, “pight”, and “qight”, if they exist).
  • [!] finds any single character except those specified: “m[!u]st” finds “mist” and “most” but not “must”; “t[!ou]ck” finds “tack” and “tick” but not “tock” or “tuck”; [!x-z] Finds any single character except those in the specified range; “t[!a-m]ck” finds “tock” and “tuck” but not “tack” or “tick”.
  • {n} finds exactly n occurrences of the previous character or expression: “re{2}d” finds “reed” but not “red”.
  • {n,} finds at least n occurrences of the previous character or expression: “re{1,}d” finds “red” and “reed”.
  • {n,m} finds from n to m occurrences of the previous character or expression: “10{1,3}” finds “10”, “100”, and “1000”.
  • @ finds one or more of the previous character or expression before something else: “me@t” finds both “met” and “meet”; “me@” (without the “t”) finds only “me” because nothing comes after it.
  • < finds the beginning of a word: “<inter” finds “interest” and “interrupt” but not “splinter”.
  • > finds the end of a word: “in>“ finds “in” and “main” but not “inspiring”.

A few things to note:

  • With wildcard searches, Word automatically matches case.
  • The following characters must be escaped with a backslash (\) when used as characters in a search: ? * [ ] { } ( ) < > ^ \.
  • The Find whole words option is not available in wildcard searches.
  • You should always turn off track changes before using wildcard searches. Bad things may happen to your document if you don’t.

Some useful links:

No comments: