How to Use Word’s Find and Replace With Regex for Specific Patterns
🔍 WiseChecker

How to Use Word’s Find and Replace With Regex for Specific Patterns

You want to locate and replace text that follows a pattern, not just an exact word. Word’s built-in Find and Replace cannot handle complex patterns like phone numbers, email addresses, or variable codes. This article explains how to use Word’s Find and Replace with wildcards, which is the closest feature to regex in the desktop application. You will learn to enable wildcard mode, construct pattern-based searches, and apply replacements for common formatting and text patterns.

Key Takeaways: Using Wildcards for Pattern-Based Find and Replace in Word

  • Ctrl+H > More > Use wildcards: Enables pattern matching similar to regex in Word’s Find and Replace dialog.
  • Find what: ([0-9]{3}) ([0-9]{3}-[0-9]{4}): Captures a phone number pattern like 555 123-4567 for reformatting or extraction.
  • Replace with: \1\2: Uses backreference codes to reorder or reformat captured groups from the original pattern.

ADVERTISEMENT

What Word’s Wildcard Find and Replace Can and Cannot Do

Word’s wildcard feature is not full regex. It supports a subset of regular expression operators designed for text patterns. You can match any single character with ?, any string of characters with , character ranges with [a-z], and capture groups with parentheses (). You cannot use lookahead, lookbehind, alternation with |, or quantifiers like {2,5} in the same way as modern regex engines. The wildcard engine works on a character-by-character basis and does not support word boundaries or non-greedy matching.

To use these patterns, you must turn on the wildcard option in the Find and Replace dialog. When wildcards are active, Word treats certain characters as operators. For example, the asterisk matches any number of characters, but it is greedy and matches as much as possible. The question mark ? matches exactly one character. Square brackets define a set or range of allowed characters. Parentheses group parts of the pattern so you can reuse them in the replacement with backreferences like \1, \2, and so on.

Prerequisites for Using Wildcard Patterns

You need Word 2010 or later on Windows. The wildcard feature is not available in Word for the web or Word for Mac in the same way. On Mac, you can access wildcards through the Find and Replace dialog by clicking the gear icon and selecting the checkbox for Use wildcards. The patterns work identically across versions, but the dialog layout differs slightly. Before you start, ensure you have a backup of your document because wildcard replacements can produce unexpected results if the pattern is too broad.

Steps to Find and Replace Text Patterns Using Wildcards

The following steps work for Word 2016, 2019, 2021, and Microsoft 365 on Windows. For Mac, the menu path is Edit > Find > Advanced Find and Replace, then click the gear icon and check Use wildcards.

  1. Open the Find and Replace dialog
    Press Ctrl+H on your keyboard. The Find and Replace dialog appears.
  2. Expand the dialog to show more options
    Click the More >> button at the bottom left of the dialog. This reveals additional checkboxes and formatting options.
  3. Enable wildcard mode
    Check the box labeled Use wildcards. The Find what and Replace with fields now accept wildcard operators. The dialog title remains the same, but the behavior changes.
  4. Enter your pattern in the Find what field
    Type a wildcard pattern. For example, to find any five-digit number, type [0-9]{5}. To find an email address pattern, type [A-z0-9._%+-]+@[A-z0-9.-]+.[A-z]{2,}. Note that Word uses { } for exact counts and [ ] for character sets.
  5. Enter the replacement pattern with backreferences
    In the Replace with field, use backreferences like \1 to refer to the first captured group from the Find what pattern. For example, if Find what is (Smith) (John), type \2 \1 in Replace with to swap the order to John Smith.
  6. Test the pattern with Find Next
    Click Find Next to see if Word highlights the correct text. Adjust the pattern if the selection is wrong. Wildcard patterns are case-sensitive by default unless you also check Match case.
  7. Apply the replacement
    Click Replace to change one occurrence at a time, or click Replace All to change every match in the document. Review the changes immediately. If the result is wrong, press Ctrl+Z to undo the replacement.

Common Wildcard Pattern Examples

Here are patterns you can copy and adapt for your own documents. Replace the placeholder text with your actual needs.

Find all words in uppercase: In Find what, type <[A-Z]{2,}> . This matches any word of two or more uppercase letters. The < and > operators mark the start and end of a word.

Find phone numbers in the format 555-123-4567: In Find what, type [0-9]{3}-[0-9]{3}-[0-9]{4}. This matches exactly three digits, a hyphen, three digits, a hyphen, and four digits.

Remove extra spaces between sentences: In Find what, type . [ ]{2,} . (with a period, space, two or more spaces, period). In Replace with, type . . (period, space, period). This reduces double spaces to single spaces after periods.

ADVERTISEMENT

If the Wildcard Search Does Not Find the Expected Text

The pattern matches nothing or too much

The most common cause is an incorrect operator. Check that you used the correct syntax for character ranges. For example, [a-z] matches lowercase letters only. To match both cases, use [A-z] but note that this also includes characters like [ and \ between Z and a in the ASCII table. A safer range for letters only is [A-Za-z]. Also verify that you did not accidentally include a space in the pattern that does not exist in the document.

Backreferences in Replace with do not work

Word uses a backslash followed by a digit, like \1, to reference a captured group. Ensure that you typed the backslash correctly. On some keyboards, the backslash key is above the Enter key. If you type a forward slash / instead, Word treats it as a literal character. Also confirm that you placed parentheses in the Find what pattern. Without parentheses, there are no captured groups to reference.

Word replaces text that should not be replaced

Wildcard patterns are greedy. The asterisk matches as many characters as possible. For example, the pattern ab applied to the text aXbYb matches aXbYb, not just aXb. To limit the match, use a more specific pattern. Instead of ab, use a[!b]@b where @ matches one or more occurrences of the preceding character or group. The exclamation mark inside brackets means not. This pattern matches a, then one or more characters that are not b, then b.

Operator Wildcard Behavior Regex Equivalent
? Matches exactly one character .
Matches any number of characters (greedy) .
[a-z] Matches one character in the range [a-z]
[!a-z] Matches one character not in the range [^a-z]
(pattern) Captures the pattern for backreference (pattern)
\1 References the first captured group \1
{n} Matches exactly n occurrences of preceding char {n}
{n,} Matches at least n occurrences {n,}

Now you can use Word’s Find and Replace with wildcard patterns to locate and modify structured text like codes, numbers, and formatted names. Start by testing a simple pattern on a small section of your document before applying Replace All. For advanced pattern matching beyond Word’s wildcard capabilities, consider using a dedicated regex tool and then pasting the cleaned text back into Word.

ADVERTISEMENT