Adobe 65009333 User Guide - Page 120

Tips for constructing GREP searches, GREP search examples

Page 120 highlights

USING INCOPY CS4 114 Text You can also use GREP Styles to apply a character style to text that conforms to a GREP expression. In fact, the GREP Styles dialog box is a good way to test your GREP expression. Add the examples you want to find to a paragraph, and then specify a character style and GREP expression in the GREP Styles dialog box. When you turn on Preview, you can edit the expression until it affects all your examples properly. See also "Create GREP styles" on page 180 "Metacharacters for searching" on page 117 Tips for constructing GREP searches Here are some tips for constructing GREP expressions. • Many searches under the GREP tab are similar to those under the Text tab, but be aware that you need to insert different codes depending on which tab you're using. In general, the Text tab metacharacters begin with a ^ (such as ^t for a tab) and GREP tab metacharacters begin with a \ (such as \t for a tab). However, not all metacharacters follow this rule. For example, a paragraph return is ^p in the Text tab and \r in the GREP tab. For a list of the metacharacters used for the Text and GREP tabs, see "Metacharacters for searching" on page 117. • To search for a character that has symbolic meaning in GREP, enter a backslash (\) before the character to indicate that the character that follows is literal. For example, a period ( . ) searches for any character in a GREP search; to search for an actual period, enter "\." • Save the GREP search as a query if you intend to run it often or share it with someone else. (See "Find/change items using queries" on page 123.) • Use parentheses to divide your search into subexpressions. For example, if you want to search for "cat" or "cot," you can use the c(a|o)t string. Parentheses are especially useful to identify groupings. For example, searching for "the (cat) and the (dog)" identifies "cat" as Found Text 1 and "dog" as Found Text 2. You can use the Found Text expressions (such as $1 for Found Text 1) to change only part of the found text. GREP search examples Follow these examples to learn how to take advantage of GREP expressions. Example 1: Finding text within quotation marks Suppose you want to search for any word enclosed in quotation marks (such as "Spain"), and you want to remove the quotation marks and apply a style to the word (so that it becomes Spain instead of "Spain"). The expression (")(\w+)(") includes three groupings, as indicated by parentheses ( ). The first and third groupings search for any quotation mark, and the second grouping searches for one or more word characters. You can use the Found Text expressions to refer to these groupings. For example, $0 refers to all found text, and $2 refers to only the second grouping. By inserting $2 in the Change To field and specifying a character style in the Change Format field, you can search for a word within quotation marks, and then replace the word with a character style. Because only $2 is specified, the $1 and $3 groupings are removed. (Specifying $0 or $1$2$3 in the Change To field would apply the character style to the quotation marks as well.) Updated 29 April 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298

114
USING INCOPY CS4
Text
You can also use GREP Styles to apply a character style to text that conforms to a GREP expression. In fact, the GREP
Styles dialog box is a good way to test your GREP expression. Add the examples you want to find to a paragraph, and
then specify a character style and GREP expression in the GREP Styles dialog box. When you turn on Preview, you can
edit the expression until it affects all your examples properly.
See also
Create GREP styles
” on page
180
Metacharacters for searching
” on page
117
Tips for constructing GREP searches
Here are some tips for constructing GREP expressions.
Many searches under the GREP tab are similar to those under the Text tab, but be aware that you need to insert
different codes depending on which tab you’re using. In general, the Text tab metacharacters begin with a ^ (such
as ^t for a tab) and GREP tab metacharacters begin with a \ (such as \t for a tab). However, not all metacharacters
follow this rule. For example, a paragraph return is ^p in the Text tab and \r in the GREP tab. For a list of the
metacharacters used for the Text and GREP tabs, see “
Metacharacters for searching
” on page
117.
To search for a character that has symbolic meaning in GREP, enter a backslash (\) before the character to indicate
that the character that follows is literal. For example, a period ( . ) searches for any character in a GREP search; to
search for an actual period, enter “\.”
Save the GREP search as a query if you intend to run it often or share it with someone else. (See “
Find/change items
using queries
” on page
123.)
Use parentheses to divide your search into subexpressions. For example, if you want to search for “cat” or “cot,”
you can use the c(a|o)t string. Parentheses are especially useful to identify groupings. For example, searching for
“the (cat) and the (dog)” identifies “cat” as Found Text 1 and “dog” as Found Text 2. You can use the Found Text
expressions (such as $1 for Found Text 1) to change only part of the found text.
GREP search examples
Follow these examples to learn how to take advantage of GREP expressions.
Example 1: Finding text within quotation marks
Suppose you want to search for any word enclosed in quotation marks (such as “Spain”), and you want to remove the
quotation marks and apply a style to the word (so that it becomes
Spain
instead of “Spain”). The expression
(")(\w+)(")
includes three groupings, as indicated by parentheses ( ). The first and third groupings search for any
quotation mark, and the second grouping searches for one or more word characters.
You can use the Found Text expressions to refer to these groupings. For example, $0 refers to all found text, and $2
refers to only the second grouping. By inserting $2 in the Change To field and specifying a character style in the Change
Format field, you can search for a word within quotation marks, and then replace the word with a character style.
Because only $2 is specified, the $1 and $3 groupings are removed. (Specifying $0 or $1$2$3 in the Change To field
would apply the character style to the quotation marks as well.)
Updated 29 April 2009