Troubleshooting
GREP is a symbolic system, and it is easy to lose track of certain formal aspects. We're not helped by GREP's interface: entering complex expression can be a challenge in such a confined space, and the miniscule type in the "Find what" and "Change to" fields doesn't help either. Nor are we warned about errors in an expression: InDesign accepts anything. Recalcitrant expressions can be frustrating, but there are a number of things to look out for when troubleshooting expressions.
Escape Characters
It is easy to forget to escape certain characters, so if an expression doesn't work, this is the first thing to check. Characters to be escaped are the ones that have a special meaning for GREP: the dot, asterisk, parentheses, straight brackets, braces, etc.
GREP Is Case-Sensitive
Remember that GREP is case-sensitive by default, which is easy to forget as InDesign's Text search has always been and still is case-insensitive by default.
Hyphens in Character Classes
In character classes, when using a hyphen, always put it first. In [a-e], the hyphen is interpreted as a range symbol; the expression matches a, b, c, d, and e. In [-ae] it is seen as hyphen, and this expression matches -, a, and e.
Parentheses
Parentheses are used a lot in GREP, so make sure there's a closing parenthesis for every opening one.
Split Complex Expressions
Partly because of its unfriendly interface, it is useful to split complex expressions into smaller ones. That way they're easier to understand and modify, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access