Members Only

How to Find Literal Instances of GREP Metacharacters in InDesign

Certain characters perform special functions in GREP. So how do you search for the actual uses of those characters?

This article appears in Issue 78 of InDesign Magazine.

Some characters, known as metacharacters, have special meanings and functions in GREP searches. For instance, a period (.) will find any character—letters, digits, spaces, tabs—anything except a paragraph return. Parentheses are used to group search strings together: (\u|\d) creates a group to find any uppercase letter or any digit surrounded by spaces. The pipe character/vertical line (|) indicates “this or that.” In all, 13 metacharacters have special meanings in GREP expressions: . $ ? ^ * ( ) [ ] { } + |. But what if you want to search for any of these actual characters in your text? For instance, you might want to find periods at the end of a sentence, not the “any character” code. That’s where the backslash (\), or “escape,” character saves the day. For example, I recently wanted to apply a GREP style to the hundreds of figure labels in 16 documents of a book. These were an uppercase letter and a period surrounded by parentheses—(A.), (B.), (C.), etc. Typing (\u.) in the GREP style field doesn’t work. It completely ignored the parentheses, and then it found any uppercase character followed by any other character. So it would match A., B., and C., as well as the An in Anyone, I’ in I’m, and my initials, SC. To get around this problem, I needed to use the backslash character. Adding the backslash in front of a metacharacter removed the special meaning and made it act like a literal character. So \( finds an open parenthesis, \) found the close parenthesis, and \. found actual periods. The complete code for my GREP Style:

\(\u\.\).

It’s easy to remember the backslash escape character, because you see it

so often in GREP. But if you need a visual cue, think of it as a magic wand that you can wave to convert an ordinary character such as u or d into a magical GREP code (\u or \d), or to reverse the spell and turn the thirteen metacharacters into ordinary characters.

Bookmark
Please login to bookmark Close

Not a member yet?

Get unlimited access to articles and member-only resources with a CreativePro membership.

Become a Member

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading comments...