GREP by Example

It may be easiest to see how GREP works—and how much of an improvement it offers over its predecessor search function—with a few examples.

First, the old way. The old wildcards from InDesign 4 (CS2) can still be used in the text-search tab of InDesign 5 (CS3). In the Text tab of the Find/Change dialog, you can use four wildcards: ^9 finds any digit, ^$ stands for any letter, ^? matches any character, and ^w is used to find any whitespace. These are useful wildcards, but they have some serious limitations: you're stuck with just these wildcards, you cannot find series of wildcards (for example, you can search one-digit numbers, two-digit numbers, etc., but not numbers of any length), and you cannot use wildcards to do replacements (you can use Map ^9 to search for instances of Map followed by a digit, but you cannot then replace Map with something else without losing the following digit).

GREP is good at simple alternation. For example, to find both centre and center, search for cent(re|er). Optionality adds more flexibility: to find both the singular and plural forms of these alternatives, search for cent(re|er)s?. The question mark says that the s should be matched if present, otherwise not. This simple regular expression, then, finds centre, centres, center, and centers.

A comparable example of flexibility is exemplified by p[aeiouy]t, which matches p followed by one vowel, followed by t, so you'll find pat, pet, pit, pot, and put (though, you'll find python and ...

Get GREP in InDesign CS3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.