GREP (regular expressions) can be a very powerful solution both for finding and formatting text that matches a specific pattern, within your InDesign documents.  You could use GREP styles to apply a particular character style to all email addresses in a document for example, or you could use GREP to do something simple like remove extra spaces at the end of each paragraph.

The two main places where you can use GREP are in the GREP styles which can be found within the Paragraph Styles formatting options, and within the Find / Change options.

Here are some useful GREP examples that you might want to try, but feel free to add your own examples in the comments section.

Grep Style Examples

Grep StyleUse
b(w+)b 1Find duplicate words that are right next to each other
£{{d.,}}+(XV)?Find a UK price formatted in various ways
b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}bFind standard email addresses
(?i)b((?:{{a-z}}{{w-}}+:(?:/{1,3}Find a URL
(?<=w)s(?=w+{{{{:punct:}}}}*r)Prevent orphaned words at end of a paragraph. Apply a character style with No break checked to the last whitespace character in a paragraph.
(?<=d)(st|nd|rd|th)sUse to add superscript to ordinal numbers such as 2nd, 15th etc..


Find and Replace Grep Examples

Grep Style to FindNew StyleUse
b(w+)b 1$1Find and remove duplicate words
^(.+r)1+$1Find and remove duplicates in a list
(“)(w+)(“)$2Find text in quotes and remove quotes
(?(ddd))?{{-. }}?(ddd){{-. }}?(dddd)($1) $2-$3Format US phone numbers in standard format

Disclaimer: The examples above have been collected over time from various forums, blogs, etc. and are not produced by ourselves. Unfortunately we didn’t keep a list of where we found them, and are not even sure who the original authors are, so can’t acknowledge them in this instance.

We use cookies to improve your browsing experience on our website and to understand where our visitors are coming from. By clicking ‘Accept cookies’, you consent to our use of cookies.