When a problem comes along. You must GREP it!

Author:
Marcus Romero
Marcus RomeroCreative Director
When a problem comes along. You must GREP it!

In this first installment of my 3 part series “Breaking Code: A Designers Guide”. We’ll be going over GREP Find and Replace and GREP styles in InDesign and how you can use them to take control of text with automatic styling.

Every designer worth a damn realizes the power behind setting up and leveraging the power of Paragraph and Character styles. Not everyone realizes though that there is a second tier of power built into Paragraph styles that is mostly unused and underutilized. Understanding this power function within Paragraph styles can push your mastery of text styling into the realm of wizardry.

GREP Styles in InDesign are formatting rules for carefully targeted characters, words, or patterns of text. The method we use to target these text snippets is a language called Regular Expressions or Regex.

A Regex pattern consists of a mix of string literals, metacharacters (operators and quantifiers) and subexpressions. Let’s examine the anatomy of a Regex Pattern.

Escape it.

The first thing you need to become familiar with is the escaping metacharacter or simply the escape character. This is the backslash \\. It is called an escape character because it is escaping out of one mode of text parsing and into another where the following character is treated differently.

(I’ve always thought of this like the theatrical device known as an aside, wherein a character speaks directly to the audience with the understanding that the speech is unheard by the other characters.)

The escape character indicates one of the two following conditions:

  1. The following character is a special character, for example:
    \t = Tab
    \s = space
    \n = forced line break
    \r = end of paragraph
  2. The following operator should be treated as a literal, for example:
    The period operator  .  means match any single character. Its escaped version  \\.   will match a single period in the copy. The escaped version of the escape character  \\\  will match a single backslash.

Try to detect it.

The next thing we must consider in the anatomy of a Regex pattern are operators (and quantifiers). An operator is a character that represents an action or process. A quantifier is an operator that describes the pattern under which the examined specimens validate a formula.

Grep it good.

Let’s work together to understand Grep for Indesign, I’ve set up several examples that we’ll work through together to understand how to set them up and how they function. We’ll continue in the screen recording below.

If any of this has piqued your interest the GREP pages at InDesign Secrets are highly useful. I hope this has been helpful for you.

If you have any questions or comments leave them below. Have a GREP expression that has been especially bothersome? I’d love to help you get it sorted out.

Keep an eye on the TXC Blog for lots of great content from our insanely talented staff. Watch this space for the second part of the series where we look at “Shell Scripting with Bash for the Creative”. We’ll go over the fundamentals of the terminal, how to customize the shell and how save the scripts we create together for reuse in the future.