![]() ![]() The required expressions are shown in Figure 1. What we need now is two expressions that combine to say “If a line contains an add Email: at the beginning”. Let us assume for the moment that is used for nothing else, so that any line that contains the symbol is an email address. ![]() Your task is to add the word Email: before each email address. The string $1 in the replacement string corresponds with what was captured in the search string, so that Figure 1 is replaced with Map 1, Figure 2 with Map 2, etc.Īs a last example, and to show that simple expressions can achieve a great deal, we’ll take this seemingly difficult task: you have an address list that contains, among other things, an email address for each person. \d matches any digit, and the parentheses surrounding \d indicate that the contents of the parenthetical should be captured. To replace the word Figure with Map when it is used to refer to an illustration – that is, when it is followed by a digit – search for Figure (\d) and replace with Map $1. To demonstrate replacement with wildcards, let’s return to the Figure example. Again, \u is the wildcard for upper-case letters, and the plus stands for “one or more”, so \u\u matches strings of at least two capital letters. For instance, to apply a character style “smallcaps” to any sequence of two or more capitals, enter \u\u in the Find What field, leave the Change To field empty, and specify the style in the Change Format field. GREP expressions can be used to style text patterns. Other homemade wildcards could be “ascender letter” and “descender letter”. This example also demonstrates how you can define your own wildcards: here we defined a wildcard “vowel” by enclosing all vowels in brackets. For instance, pt matches p followed by one vowel, followed by t, so you’ll find pat, pet, pit, pot, and put (though you’ll find pyt in python and pat in spat as well we’ll see later how to do whole-word-only searches). More flexibility is offered by so-called character classes. This simple GREP, then, finds centre, centres, center, and centers. The question mark says that the s should be matched if present, otherwise not. Optionality adds more flexibility: to find both the singular and plural forms of these alternatives, search for cent(re|er)s?. For example, to find both centre and center, search for cent(re|er) alternatives are separated by pipe symbols ( ?|?). The GREP expression \u\l finds an upper-case letter \u followed by one or more lower-case letters \l . Figure \d matches the literal text Figure followed by any number (2, 34, 121, etc.): \d stands for digit, the plus sign means “at least one”. For example, you can look for series of digits rather than for a single digit. In contrast, with GREP you mainly look for patterns. The four wildcards in the Text tab are useful, though rather limited – for instance, you can’t use them for replacements, only for searching. When you use any of these wildcards, you’re no longer looking for literal text, but for a pattern. Thus with Figure^w^9 you search for the literal text Figure followed by any space, followed by a digit. But in the Text tab you can use some wildcards: ^9 finds any digit, ^$ stands for any letter, ^? matches any character, and ^w is used to find any whitespace. InDesign’s text search is used mainly for searching literal text: when you search for cats, you find just that (disregarding settings such as case-sensitivity and whole-word only). ![]() But first a quick comparison with InDesign’s Text search, which is useful because the comparison reveals GREP’s strength. It may be easiest to see how GREP works with a few examples. This is an excerpt from GREP in InDesign by Peter Kahrel.
0 Comments
Leave a Reply. |