Adobe InDesign find and change using GREP

From Training Material
Jump to: navigation, search

Introduction

GREP is advanced version for find and change GREP expression can repairing and changing text for your adventage.

On the GREP tab of the Find/Change dialog box, you can construct GREP expressions to find alphanumeric strings and patterns in long documents or many open documents. You can enter the GREP metacharacters manually or choose them from the Special Characters For Search list. GREP searches are case-sensitive by default.

Choose Edit > Find/Change, and click the GREP tab.


Metacharacter for Text

Expression Search string
Class of characters [ ] [abc] Finds the letter a, b, or c.
Beginning of paragraph ^ ^~_.+

This searches the beginning of the paragraph

(^) for an em dash

(~_) followed by any character

( . ) one or more times (+).

Negative lookahead

(?!pattern)

InDesign (?!CS.*?)

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

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).

Groupings

( )

(quick) (brown) (fox)
Non-marking parentheses

(?:expression)

(quick) ($:brown) (fox)
Case-insensitive on

(?i)

(?i)apple

You can also use (?i:apple)

Case-insensitive off

(?-i)

(?-i)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.

Multiline off

(?-m)

(?-m)^\w+
Single-line on

(?s)

(?s)c.a

The searches for any character ( . ) between the letters c and a. The (?s) expression matches any character, even if it falls on the next line.

(.) matches anything other than a paragraph return. (?s)(.) matches anything, including paragraph returns.

Single-line off (?-s)c.a
Repeat number of times

{ }

b{3} matches exactly 3 times

b(3,} matches at least 3 times

b{3,}? matches at least 3 times (shortest match)

b{2,3} matches at least 2 times and not more than 3

b{2,3}? matches at least 2 times and not more than 3 (shortest match)

Metacharacter for Search

Character: Text tab: GREP tab:
Tab Character ^t \t
End of Paragraph ^p \r
Forced Line Break ^n \n
Any Page Number ^# ~#
Current Page Number ^N ~N
Next Page Number ^X ~X
Previous Page Number ^V ~V
* Any Variable ^v ~v
Section Marker ^x ~x
* Anchored Object Marker ^a ~a
* Footnote Reference Marker ^F ~F
Bullet Character ^8 ~8
Japanese Bullet ^5 ~5
Caret Character ^^ \^
Backslash Character \ \\
Copyright Symbol ^2 ~2
Ellipsis ^e ~e
Tilde ~ \~
Paragraph Symbol ^7 ~7
Registered Trademark Symbol ^r ~r
Section Symbol ^6 ~6
Trademark Symbol ^d ~d
Open Parenthesis Character ( \(
Close Parenthesis Character ) \)
Open Brace Character { \{
Close Brace Character } \}}
Open Bracket Character [ \[
Close Bracket Character ] \]
Em Dash ^_ ~_
En Dash ^= ~=
Discretionary Hyphen ^- ~-
Nonbreaking Hyphen ^~ ~~
Ideographic Space ^( ~(
Em Space ^m ~m
En Space ^> ~>
Third Space ^3 ~3
Quarter Space ^4 ~4
Sixth Space ^% ~%
Flush Space ^f ~f
Hair Space
Nonbreaking Space ^s ~s
Nonbreaking Space (fixed width) ^S ~S
Thin Space ^< ~<
Figure Space ^/ ~/
Punctuation Space ^. ~.
^ Clipboard Contents, Formatted ^c ~c
^ Clipboard Contents, Unformatted ^C ~C
Any Double Quotation Mark " "
Any Single Quotation Mark ' '
Straight Double Quotation Mark ^" ~"
Double Left Quotation Mark ^{ ~{
Double Right Quotation Mark ^} ~}
Straight Single Quotation Mark ^' ~'
Single Left Quotation Mark ^[ ~[
Single Right Quotation Mark ^] ~]
Standard carriage return ^b ~b
Column Break ^M ~M
Frame Break ^R ~R
Page Break ^P ~P
Odd Page Break ^L ~L
Even Page Break ^E ~E
Discretionary Line Break ^k ~k
Right Indent Tab ^y ~y
Indent to Here ^i ~i
End Nested Style Here ^h ~h
Nonjoiner ^j ~j
* Running header (paragraph style) variable ^Y ~Y
* Running header (character style) variable ^Z ~Z
* Custom text variable ^u ~u
* Last page number variable ^T ~T
* Chapter number variable ^H ~H
* Creation date variable ^S ~S
* Modification date variable ^o ~o
* Output date variable ^D ~D
* File name variable ^l (lowercase L)

~l (lowercase L)

* Any Digit ^9 \d
* Any character that is not a digit \D
* Any Letter ^$ [\l\u]
* Any Character ^? . (inserts period in Change To)
* White Space (any space or tab) ^w \s (Inserts space in Change To)
* Any character that is not a white space \S
* Any word character \w
* Any character that is not a word character \W
* Any uppercase letter \u
* Any character that is not an uppercase letter \U
* Any lowercase letter \l
* Any character that is not a lowercase letter \L
^ All Found Text $0
Found Text 1-9 $1 (specifies the number of the grouping found, such as $3 for the third grouping; groupings are enclosed in parentheses)
* Kanji ^K ~K
* Beginning of Word \<
* End of Word \>
* Word Boundary \b
* Opposite of Word Boundary \B
* Beginning of Paragraph ^
* End of Paragraph [location] $
* Zero or One Time  ?
* Zero or More Times *
* One or More Times +
* Zero or One Time (Shortest Match)  ??
* Zero or More Times (Shortest Match) *?
* One or More Times (Shortest Match) +?
* Marking Subexpression ( )
* Non-marking Subexpression (?: )
* Character Set [ ]
* Or
* Positive Lookbehind (?<= )
* Negative Lookbehind (?<! )
* Positive Lookahead (?= )
* Negative Lookahead (?! )
* Case-insensitive On (?i)
* Case-insensitive Off (?-i)
* Multiline On (?m)
* Multiline Off (?-m)
* Single-line On (?s)
* Single-line Off (?-s)
* Any alphanumeric character [ [:alnum:]]
* Any alphabetic character [ [:alpha:]]
* Any blank character, either space or tab [ [:blank:]]
* Any control character [ [:control:]]
* Any graphical character [ [:graph:]]
* Any printable character [ [:print:]]
* Any punctuation character [ [:punct:]]
* Any character whose code is greater than 255 (applies only to the wide character traits classes) [ [:unicode:]]
* Any hexadecimal digit character 0-9, a-f, and A-F [ [:xdigit:]]
* Any character of a certain glyph set, such as a, à, á, â, ã, ä, å, A, À, Á, Â, Ã, Ä and Å [ [=a=]]
* Can be entered in the Find What box only, not the Change To box.
^ Can be entered in the Change To box, not the Find What box.

GREP

Letter

Digits

any Digit

any Character

Period

Only a,b or c

Not a, b, nor c

Characters a to z

Numbers 0 to 9

m Repetition

m to n Repetition

Zero or more repetitions

One or more repetitions

Optional

Any whitespace

Starts with

Ends with

Group

Subgroup

Varible content

Match a or b

Any alphanumeric character

Any non-alphanumeric character

Any non-digit character

Any non-whitespace character

Examples expression and result

Writing expression

Exercise expression