There are a few things in InDesign that send the most seasoned of designers screaming and running for the proverbial hills. I’ve been known to pretend I have to take an important call when the topic of XML or indexing arises. Another subject in that same realm is the scary-sounding, acronymic GREP. That’s right, I said it. GREP. I’m not going to go into great detail here, since there are so many great places to get up to speed on the subject. [Coincidentally, InDesign Secrets’ GREP resource page is a great place to start]. However, I AM going to show you that you can harness the power of GREP in InDesign, without actually knowing much about the subject.
In a nutshell, GREP in InDesign is a feature that lets you find and change patterns of text instead of a specific text string, as in a regular Find/Change operation. Once a pattern is found, you can use GREP to edit it, such as applying formatting, removing duplicates, replacing some characters, and so on.
The great news is you already have GREP searches available to you. Navigate to the Find/Change dialog box (Edit > Find/Change) and head to the Query pull-down menu. When you click on the menu, you might notice there are two sections, one for Text queries and the other for GREP ones. (When you create and save any Object Find/Change queries, they’ll appear in a new third section.) InDesign ships with a few “starter” queries for Text and GREP.
Most of the built-in GREP queries help you quickly clean up typical problems in text that would take a long time to clean up manually, or even with a Text Find/Change. While useful even if you’ve entered the text into InDesign yourself, where I find these searches most handy is when I’ve been given text say in, oh let’s say Word format, which can come in quite messy.
Below are explanations of the text-cleaning GREP queries built into InDesign, and what they do.
Multiple Return to Single Return
This query searches for all of the unnecessary paragraph returns in your text, while leaving the important ones intact. If you were to do a simple text search using find/change, you’d have to manual advance through the list to be sure not to delete the ones you need. The GREP string takes care of that for you.
The Multiple Return to Single Return GREP search string looks like this: ~b~b+. It’s searching for a break character (~b), followed by another one. Having the second one listed ensures the single one you need to indicate a new paragraph stays. After ~b~b, you’ll see a little plus sign. That indicates “one or more times.” So that superfluous return will occur at least once, and maybe even more. That string finds the pattern, and the information in the Change to field (\r) indicates to replace the found text with a single paragraph return.
Dashes to En Dashes
If the person that entered the text you’re now tasked with cleaning up, doesn’t know an en dash from a hyphen, you can use the Dashes to En Dashes GREP string to fix his shortcomings. Choosing this query and looking at the Find what field might make your head spin a bit. The first time I saw it and tried to decipher it, I was considering a trip to London to solicit help from the Rosetta Stone. Once I broke it down into smaller chunks, I discovered it really is a rather simple query.
The Dashes to En Dashes query looks for the pattern of either (A) any type of white space, followed by a dash (hyphen), followed by any type of white space, (B) a dash followed by any type of whitespace, or (C) any type of white space followed by a dash. Whew! I’ll just let the screenshot speak for itself, instead of copying the string here. Keep in mind, the bulk of that code is describing white space characters, so it’s not as scary as it might seem. The text in the Change to field is simply a space, followed by the representation for an en dash, followed by another space. I’ll leave the debate up to you whether or not you should use a full space—or no space at all—before and after any dash, however if you don’t want the spaces, simply replace them in the Change to field with another space or remove them completely.
Remove Trailing Whitespace
How many people just love the trailing whitespace at the end of a paragraph? Hint: none. Now, I know for a lot of people, it’s not really a big deal. But, with a program like InDesign that handles spacing and balancing and hyphenation automatically, my feelings are, “Why give it false information like extra spaces sprinkled throughout the text?” Whatever your opinion, it’s probably a good idea to run the Remove Trailing Whitespace query on imported text and not take any chances.
After the novel that was the Dashes to En Dashes query above, the string for this query is relatively short and sweet (\s+$). That string basically says to search for any space character appearing one or more times, followed by the end of a paragraph. Note that this is the location of the paragraph end, as opposed to the paragraph return character. The Change to field for this query is blank, which just tells InDesign to delete the found text—the space(s) at the end of the paragraph.
Multiple Space to Single Space
If you’ve ever used the text search of “find space-space” and replace with “space,” imagine me looking you dead in the eye and telling you to “STOP THAT!” The biggest flaw with the text search is that you assume the writer of the offending copy only put one extra space after the period. Or that he only used regular spacebar spaces. Or than anything was done consistently. The GREP query takes all of those annoying possibilities into account and laughs in the copy’s face.
The “Find what” GREP string is best left to a screenshot, but like Dashes to En Dashes, it covers its bases by listing all the possible white space characters that may or may not be in the text. After that, there is a number 2, followed by a comma, enclosed in curly brackets. That little string states that the combination of white space characters must occur “two or more times” to fit the pattern. The “Change to” field is a simple spacebar space, to replace whatever crazy concoction of spaces the writer might have included.
Make it So
Whichever query you’ve chosen, choose whether to search by story, document, or selection and change one at a time or wholesale across your selection. Feel free to make any tweaks to the existing queries then hit the Save Query button for re-use on your next set of text you are tasked with cleaning up.
GREP can be fun and—if you only need these text cleanup helpers—doesn’t even require knowing much about it to make it an extremely useful tool.Tags