h1

Word: Find text with angled brackets and replace the text with a character style

November 2, 2019

Here’s one I heard of today, and how I solved it. The person has a Word document with various words and phrases surrounded by double angled brackets, as in <<this is my phrase>>. They want to apply a character style to any text surrounded by angle brackets, and delete those brackets.

I always like a challenge like this, so here’s my solution:

  1. Press Ctrl+H to open the Find and Replace window.
  2. Click More.
  3. Select the Use wildcards checkbox.
  4. In the Find what field, type: (\<\<)(*)(\>\>)
  5. In the Replace with field, type: \2
  6. Click Format, then select Style.
  7. Choose the character style you want to apply (character styles are indicated with a lowercase ‘a’ to their left), then click OK.
  8. The character style’s name should be listed directly underneath the Find what box—make sure that this is the case.
  9. Click Find Next, then click Replace if you are satisfied that the correct phrasal structure has been selected.
  10. Assuming that replace worked as you wanted it to, and you are confident the result looks as you expect, click Replace All. (If in doubt, keep clicking Find Next, then Replace.)

How this works:

  • The Find is broken up into three elements, each surrounded by parentheses:
    • The first element contains the opening two angled brackets.
    • The second contains an asterisk wildcard character for any character and any number of characters.
    • The third contains the closing two angled brackets.
  • In the first and third elements of the Find, the angled brackets are each preceded by a \ because an angle bracket is a special character in wildcard searches and therefore must be ‘escaped’ so that Word treats it as a normal character. The ‘escape’ character is the \
  • In the Replace, \2 tells Word to replace the second element (the text and all characters between the angled brackets) with itself (i.e. make no changes), and to apply the character style you chose to that replaced text.
  • By omitting \1 and \3 in the Replace (representing the first and third elements of the Find), Word will effectively delete the opening and closing angled brackets.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: