Beruflich Dokumente
Kultur Dokumente
The new GREP tab in InDesign You know you’re a geek when you get excited about most common problems in imported text. We’ve
CS3’s Find/Change opens a the Find/Change dialog box. But this dialog box has
long been a powerful tool for efficiently handling large
also included a file with the raw text. This file,
named “GREP Example,” is attached to this PDF
powerful set of commands. amounts of text. Now, in CS3, the Find/Change dialog document. Open it and you can follow along.
1
box has gotten a complete overhaul, and it’s not just
a little better… it’s total geek heaven. Not only can Examine the text for searchable patterns
you now search for object attributes (such as color, The text in each of the text frames is
strokes, and so on) and special glyphs, InDesign CS3 typical of the kind of text that might
lets you use GREP expressions for use in search strings. come in from email documents. We need to
GREP (which
���������������������������������������������
stands for General Regular Expression apply the Signature paragraph style to the text
Parser) wasn’t
����������������������������������������������
invented for InDesign CS3. Programmers that is preceded by an em dash (�Figure 2)�.
have used GREP for years to wrangle complicated
search-and-replace operations within files.
With GREP, you can build searches that contain
specialized substitutions and wild cards. For instance,
you can look for all the text between parentheses
and apply a character style. This seemingly simple
task is basically impossible without GREP.
Chances are, you’re not a programmer. So
why should you care? Because once you get past
the mindset that you don’t need GREP, you’ll be
amazed by how much time you’ll save. And since
the Adobe engineers have included premade
search strings for some of the most common search
requests, you don’t even have to know the codes. Figure 2: The text contains many strings of characters and non-
printing characters that need to be cleaned up. Our first task is to
This tutorial, which documents the creation of restyle the text that comes after the em dashes..
a brochure for a fictitious Hawaiian visitor center
Figure 1:The imported text in this three-fold brochure spread is full
of weird characters typical of text from email messages. Removing (Figure 1), will help you understand how to use
the characters and reformatting by hand would be tedious. GREP expressions to quickly clean up some of the
2
shown in the portion of text shown in Figure 4.
name your query.
Use the new Find/Change dialog box
The query then appears inside the preset list. This
As soon as you choose Edit > Find/Change, list is divided into four sections. The first section is for
you’ll notice the tabs that let you select each Text searches, the second for Grep searches, the third
of the four types of searches (Figure 3). The Text for Glyph searches, and the fourth for Object attribute
tab gives you controls similar to previous versions searches.
What’s really cool about this list is when you choose
of InDesign. The GREP tab gives you the controls
one of the presets, the tab automatically changes to the
for regular expression searches. The Glyph tab lets correct type of search.
you search and replace specific glyph characters.
3
The Object tab lets you search and replace object
attributes. To do GREP searches, click the GREP tab. Delete multiple characters and spaces
Our next cleanup task is to delete the
angle brackets. It’s simple to find those
brackets; type > in the Find What field.
However, there may be more than one bracket on Figure 4: The text as it appears after the quoted angle brackets and
each line. With a simple Text search, we’d have to run spaces are deleted.
4
the search several times. With GREP we can set the
search to look for multiple instances of the brackets. Find characters in position
Choose Repeat > One or More times from the We can find the code for the em dash in
Special Characters for Search menu to insert a + GREP searches by choosing Symbols >
after the bracket. (Of course, once you know that Hyphens and Dashes > Em dash from the Special
code, you could just type the + character yourself.) Characters for Search menu (Figure 5). This
This find several angle brackets in a row. inserts the code ~_ into the Find what field.
Figure 3: The four category tabs, Text, GREP, Glyph, and Object, in However, we also need to delete the spaces after However, there are other em dashes within the
the Find/Change dialog box let you switch between each of the the angle brackets. So type a space and then another text that we don’t want to convert. So we need
types of searches..
+ sign (indicating one or more space characters). to specify only those em dashes that begin
Leave the Change What field blank and click the paragraphs. Put your insertion point at the front
Clear Specified Attributes icon to the right of the of the Find what field (before the ~_ code) and
Change Format section (that’s the icon that looks like choose Locations > Beginning of Paragraph.
5
Find field. The code $2 inserts the second items. And the
This inserts a ^ in front of the em dash code: Delete spaces that may not be there code $3 inserts the third items.
^~_, which means “look for all em dashes at the It’s rather simple to delete the forced line Using these found codes allows you to add a a period
beginning of a paragraph.” We can then click the breaks (sometimes called “soft returns”): Choose in between the digits.
Specify Attributes to change icon for the Change Forced Line Break to insert the GREP code \n. The
challenge is that some of those line breaks have If we replace all line breaks with spaces, we could
a space in front of them while others don’t. If we get two spaces in a row, requiring another cleanup.
simply delete the breaks that aren’t followed by a GREP gives us the flexibility to search for
space, we could have two words jammed together. something that may or not exist. The ? code says that
something can exist zero or one time. We can also use
Tip: Watch the codes
the Wildcards > Any White Space to insert the code
Many searches under the Text tab are similar to those \s. This ensures that we capture all types of spaces.
under the GREP one. But you need to insert different With the expression \s?\n we look for any
codes depending on which section you’re in. white space that may or may not be there, followed
For instance, under the Text section a tab character is ^t, by a line break that will definitely be there.
while the GREP code is \t. But if you think that the only
difference is the caret or the slash, look at a paragraph re- We then enter a single space in the Change field.
turn. In the Text searches, the code is ^p, but it’s \r under This means that only one space will replace the
the GREP section. See the table attached to this PDF for a line breaks. For those line breaks that don’t have
complete list of all the Text and GREP search codes. a space before them, it will avoid word collisions.
If you’re like me and you enter your codes manually, in- For those line breaks that do have a space before
stead of using the search menus, you need to remember
Figure 6: By leaving the Change to field blank, you can assign a under which section you’re working. them, it avoids creating multiple spaces.
paragraph style to all the text in the paragraph.
6
lowercase letters (\l), any digits (\d), any spaces (\s),
Delete multiple returns any character (.), or any word characters (\w). If we
Here’s another task that could be handled in an add the * after each character code, it will find any of
ordinary Text search: Look for two paragraph those characters that may appear zero or more times.
returns and replace them with a single return. However, this code isn’t quite ready to do what we
But, as anyone who has ever done such a search want, as you’ll see in the next step.
8
knows, you have to rerun the search several times
when there are three or more returns in a row. Change just the text inside the quotes
Happily, Adobe included a preset query to With the code as it stands in the previous step,
handle this situation in a single search. You can any changes we apply in the Change Format
choose the preset by using the Query menu Figure 8: Now we’ve taken care of those pesky forced line breaks.
field will be applied to all the found text. But
�������
we
at the top of the dialog box (Figure 7). need to style just the text within the quotes.
When you choose Multiple Return to Single The + sign indicates that the second break Fortunately, there’s a way to specify just one
Return, InDesign inserts the strings for both character appears one or more times. So if there is part of the found text that should be changed.
the find and the change fields. ~b finds a another break character after the second one, that We need to separate the code into three groups
standard carriage return; \r looks for that and character will also be included in the found text. using parenthesis. So we now write the code
column breaks, frame breaks, and so on. Now, your text should look like Figure 8. as (~{)(\u*\l*\s*.*\w*\d*)(~}).