Learn // GREP for InDesign

InDesign GREP tutorial for beginners

A practical guide to InDesign Find/Change patterns. No programming needed. Every example shows hidden characters the way InDesign does.

What is GREP?

GREP (Global Regular Expression Print) lets you find and replace kinds of text, not just exact words.

  • Normal Find/Change: find “cat”, replace with “dog”
  • GREP Find/Change: find “two or more spaces”, replace with “one space”, wherever they are
Real-world example: instead of fixing 500 double spaces by hand, one GREP pattern finds all of them in seconds.

Where to find GREP in InDesign

  1. Press Ctrl+F
  2. Click the GREP tab
  3. Type the pattern in Find what and the replacement in Change to
  4. Click Find Next a few times, then Change All

Your first pattern EASY

Start with the most common problem in manuscripts: double spaces. Typing two spaces in Find works, but only for exactly two. GREP handles any number:

That’s it, your first GREP. {2,} means “two or more”. It’s called a quantifier, and you’ll use it all the time.

Wildcards and special characters EASY

Wildcards stand for a type of character:

PatternMeansMatches
.Any single charactera, B, 3, @, space
\dAny digit0 to 9
\wAny word characterletters, digits, underscore
\sAny white spacespace, tab, return
\tTabthe tab character
\rParagraph returnend of a paragraph
\nForced line breakShift+Enter

All of InDesign's special characters, with the token for each and how InDesign shows it: InDesign GREP special characters.

Watch out: these characters have a special meaning: . * + ? ^ $ [ ] ( ) { } | \. To find them as plain text, put a backslash in front: \. \* \?

Quantifiers: how many? EASY

QuantifierMeansExample
*Zero or moreab*c finds ac, abc, abbc
+One or moreab+c finds abc, abbc, not ac
?Zero or onecolou?r finds color and colour
{3}Exactly 3\d{3} finds 123
{2,4}Between 2 and 4\d{2,4} finds 12, 123, 1234
{2,}2 or more\s{2,} finds runs of white space

Anchors: where? MEDIUM

Anchors match a position, not a character:

AnchorMeansExample
^Start of a paragraph^The finds “The” only at the start
$End of a paragraph\.$ finds a period at the end
\bWord boundary\bcat\b finds “cat”, not “category”

Groups and capturing MEDIUM

Parentheses ( ) remember what they found, so you can reuse it in Change to as $1, $2, and so on. $0 is the whole match.

Practical examples

Patterns you can use today:

Typography

Cleanup

Find many more in the GREP Library, each with a before and after example.

Common mistakes

MistakeWhat happensFix
Forgetting to escape. matches any character, not only a periodUse \.
Greedy matching".*" runs from the first quote to the last one in the paragraphUse ".*?" for the shortest match
Casethe doesn’t find “The”Use [Tt]he or (?i)the
A space that finds nothingA space typed in Find is a regular space. Em, en, thin and nonbreaking spaces are other characters, each with its own tokenTurn on Type, Show Hidden Characters to see which space it is, then use its token: ~m for an em space, ~S for a nonbreaking space, or \s for any white space. All space tokens
Change All blindlyA wrong pattern changes hundreds of places you didn’t meanClick Find Next a few times first, or use Preview in GREP Batch Processor
Golden rule: check a few matches with Find Next before Change All. And keep a copy of important documents.

Resources

ResourceWhat it is
Treasures of GREPFacebook group where InDesign users share and improve GREP
GREP in InDesignThe classic book by Peter Kahrel
CreativeProArticles and tutorials, including the former InDesignSecrets
Regex101Online regex tester. Close to InDesign GREP, but InDesign codes like ~_ or ~S are not supported there

Next steps