Members Only

GREP of the Month: This or That

The vertical bar helps when you need options in your GREP searches.

This article appears in Issue 81 of InDesign Magazine.

Sometimes you need to find several different strings of text in your document. If you know the specific strings, you could always do individual searches, using the Text tab of InDesign’s Find/Change dialog box. But you can save time by writing a single GREP expression that covers each string you’re looking for. Plus, using a “this or that” expression lets you build the search into a paragraph style. The magic “either/or” symbol in GREP is the vertical slash |, or pipe, typically found by pressing Shift+backslash. InDesign GREP or expression vertical bar In a GREP string, the expression will look for everything on either side of the pipe. For instance, the expression candy apple|banana finds candy apple or banana (but not candy banana). An example of this in a find/change search would be to find a list of product names Anvils|Dynamite|Rocket Skates and change it to $0~d, which means add the trademark symbol ~d to the found text $0. Since GREP wants to take everything to the sides of the pipe, you often need to isolate the list of strings you’re looking for. You do this by creating a subexpression, which involves encasing the list in parentheses. If I searched on ACME Anvils|Dynamite|Rocket Skates, I’d get “ACME Anvils” or “Dynamite” or “Rocket Skates”. However, if I search for ACME (Anvils|Dynamite|Rocket Skates), I’ll find ACME Anvils, ACME Dynamite, or ACME Rocket Skates. You can also use a subexpression to isolate parts of a word, for instance to find alternate spellings. Searching adapt(o|e)r will find adaptor or adapter. You could use adaptor|adapter, but the former is quicker and cleaner. One thing to remember is that GREP works in a logical fashion when applying GREP Styles. If you search for cat|category, InDesign won’t find “category” because

it finds “cat” in the word first. So put the longest word first in the list, like category|cat. Erica Gamet

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 (4)

Leave a Reply

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

Loading comments...