GREP of the Month: Word Boundaries
How to target GREP searches to specific words or parts of words to avoid finding them in the wrong places
This article appears in Issue 80 of InDesign Magazine.
Sometimes a simple text search in InDesign can find (or change!) more than you bargained for. I remember occasions where I had to find and change the name of a product to a bold style, only to later find out I had accidentally also converted regular words in the same text. For example, looking for the word “light” accidentally also changes the word “highlight” or “lightning.” GREP is a great way to look for specific text, but when that text appears inside other words, you can find yourself in trouble. To counter this behavior and stop GREP from finding your search criteria within other words, you can use the Beginning of Word (<) and End of Word (>) expressions. You might think why can’t I just use the ‘whole word’ button in the Find/Change window? Well, for a simple reason: because that button doesn’t exist when you perform a GREP search. So… Imagine you have these words in the same text: cat, catalog, wildcat. Looking for the word cat will find all instances in any location, including within the other words. But adding the < and/or > characters tells InDesign to find only the word cat at the beginning or end of your text. For example, <cat will find cat and catalog (so just the first three letters in the word catalog), but not wildcat. And cat> will find cat and wildcat (so just the last three letters of wildcat), but not catalog. And the combination is even more powerful, and will act as the “whole word” option that you can use when doing a regular text Find/Change. So using <cat> will find only the word cat and nothing else, nowhere else. Be careful, though. InDesign considers something to be a “word” when this word is preceded or followed
by spaces, beginning or end of story or paragraphs, but also punctuation. So the cat in www.cat.com is also considered to be a separate word and will also be found.
Commenting is easier and faster when you're logged in!
Recommended for you
Formatting in a Flash
How do you take 50 unstyled, manually formatted Word files and turn them into a...
Using Find/Change Case in InDesign
Learn how to use Find/Change to modify the case of text in InDesign
