Word: Replace and reformat text inside square brackets using wildcardsJune 20, 2011
My husband wanted to select a long column of text and find any text that was inside square brackets and reformat it so that the text — and the square brackets — was 4 pt and blue (no, I don’t know why either…).
This is an ideal job for using wildcards in Word’s find and replace. However, square brackets are special characters in wildcard searches, so they have to be treated differently. With some help from http://word.mvps.org/faqs/general/usingwildcards.htm and a bit of trial and error, I figured it out. I explain what all the settings mean after these steps, if you’re interested. Meantime, here’s my solution, which works in all versions of Word:
- Select the text you want to change (e.g. entire document, selected paragraphs, selected columns or rows of a table).
- Press Ctrl+H to open the Find and Replace dialog box.
- Click the More button.
- Select the Use wildcards check box.
- Put your cursor into the Find what field.
- Type the following exactly (or copy it from here): (\[)(*)(\])
- Go to the Replace with field and type: \1\2\3
- Click the Format button, and select Font.
- On the Font dialog box change the settings to what you want — in my husband’s case, this was 4 pt and blue — then click OK. Your Find and Replace dialog box should now look like this:
- Click Replace All.
- Once all replacements have been made, check that you got what you expected before making further changes to the document. If it’s all OK, save your document with the new changes.
What it all means
The three elements of the Find are:
- (\[) — You need to find a specific character (the opening square bracket), so you need to enclose it in parentheses. However, because the square brackets are special wildcard characters in their own right, you need to tell Word to treat them as normal text characters and not as special characters, so you put in a backslash ‘\‘ (also known as an ‘escape’ character) before the [.
- (*) — This tells Word to look for any characters after the opening square bracket. There’s no limit on what sort of characters (alpha, numeric, or symbols) Word is to find, or on how many there are.
- (\]) — This tells Word to stop the find at the first closing square bracket it finds after an opening square bracket followed by any other characters. As with the opening square bracket (1. above), the closing square bracket is a special wildcard character, so needs a backslash in front of it for Word to treat it as ordinary text, and it needs to be enclosed in parentheses as it’s an exact match you want.
There are no spaces between any of these elements — the aim is to find a string such as [green frog] and replace it with exactly the same text but formatted in a different color and with a difference font size.
The three elements of the Replace are:
- \1 — Tells Word to replace the first element of the Find with what was in the Find (the opening square bracket).
- \2 — Tells Word to replace the second element of the Find with the same text as what was found. In other words, keep the exact text as was found, but change it’s font size and color.
- \3 — Tells Word to replace the third element of the Find with what was in the Find (the closing square bracket).
As with the Find elements, there are no spaces between these elements. You still want [green frog], not [ green frog ].
- Replace text in quotes with bold: https://cybertext.wordpress.com/2008/05/14/word-2003-replac-text-in-quotes-with-bold-text/
- Replace excess spaces: https://cybertext.wordpress.com/2009/01/11/word-replace-excess-spaces/
- Find and replace any number of spaces: https://cybertext.wordpress.com/2010/09/13/word-find-and-replace-any-number-of-spaces/
- Change the number of spaces after a period: https://cybertext.wordpress.com/2009/01/23/word-change-the-spaces-after-a-period/
[Links last checked June 2011]