beautypg.com

Adobe InDesign CS4 User Manual

Page 163

background image

155

USING INDESIGN CS4

Text

206 555 3982 = $1 $2 $3

Additional GREP examples
Experiment with these examples to learn more about GREP searches.

Expression

Search string

Sample text

Matches (in bold)

Class of characters

[ ]

[abc]

Finds the letter a, b, or c.

Maria cuenta bien.

Mariacuentabien.

Beginning of
paragraph

^

^~_.+

This searches the beginning of the paragraph
(^) for an em dash (~_) followed by any
character ( . ) one or more times (+).

“We saw—or at least we
think we saw—a purple
cow.”

—Konrad Yoes

“We saw—or at least we think we
saw—a purple cow.”

—Konrad Yoes

Negative lookahead

(?!pattern)

InDesign (?!CS.*?)

The negative lookahead matches the search
string only if it is not followed by the specified
pattern.

InDesign, InDesign 2.0,
InDesign CS, and InDesign
CS2

InDesign, InDesign 2.0, InDesign
CS, and InDesign CS2

Positive lookahead

(?=pattern)

InDesign (?=CS.*?)

The positive lookahead matches the search
string only if it is followed by the specified
pattern.

Use similar patterns for negative lookbehinds
(?pattern) and positive lookbehinds
(?<=pattern).

InDesign, InDesign 2.0,
InDesign CS, and InDesign
CS2

InDesign, InDesign 2.0, InDesign
CS, and InDesign CS2

Groupings

( )

(quick) (brown) (fox)

The quick brown fox jumps
up and down.

The quick brown fox jumps up
and down.

All found text = quick brown fox;
Found Text 1= quick; Found Text 2
= brown; Found Text 3= fox

Non-marking
parentheses

(?:expression)

(quick) ($:brown) (fox)

The quick brown fox jumps
up and down.

The quick brown fox jumps up
and down.

All found text = quick brown fox;
Found Text 1= quick; Found Text 2
= fox

Case-insensitive on

(?i)

(?i)apple

You can also use (?i:apple)

Apple apple APPLE

AppleappleAPPLE

Case-insensitive off

(?-i)

(?-i)apple

Apple apple APPLE

Apple apple APPLE

Multiline on

(?m)

(?m)^\w+

In this example, the expression looks for one or
more (+) word characters (\w) at the beginning
of a line (^). The (?m) expression allows all lines
within the found text to be treated as separate
lines.

(?m)^\w matches the beginning of each
paragraph. (?-m)^\w matches only the
beginning of the story.

One Two Three Four Five Six
Seven Eight

One Two ThreeFour Five SixSeven
Eight

Updated 18 June 2009