All Articles InDesign
InDesign: Understanding GREP Styles
Iain Anderson on Wed, April 16th | 0 comments
If you've heard of GREP but are either not sure what it is or whether it can be useful for you with InDesign, then this article by Iain Anderson is for you.

I’ll be blunt: GREP is a tool for Nerds. And GREP Styles are a tool for Nerds Who Really Like InDesign. Still, it’s a remarkably useful tool, and it could prove to be quite handy, as it lets you search for a complex (or simple) series of characters, and apply a Character Style to just those characters automatically. Let that sink in a little, then read on.

So what’s GREP?

The Global Regular Expression Parser lets you find nearly anything you want, using either a complex series of codes, or (thankfully) a series of drop-down menus. It’s not just for a specific word, though; you can search for wildcards, for some item repeated one or more times, for a phrase you want to re-style.

Here’s a super-fancy GREP preset from the more traditional Find/Change dialog.

Here’s a super-fancy GREP preset from the more traditional Find/Change dialog.

Even better, you can separate parts of the search terms and replace them in a different order. It’s an obscure form of magic from the land of Unix. You could, for example, search for:

  • two spaces in a row
  • the name of your company 
  • four digits followed by an apostrophe followed by an s
  • the first letter at the start of a paragraph
  • 15 or more characters between quote marks

And what do GREP Styles do again?

They let you apply a Character Style to something you found. So, without changing any of the source text—potentially important if it’s still linked to a changing document—you could:

  • squish those two spaces into the space of one
  • embolden and capitalize the name of your company
  • italicize a decade
  • capitalize the first letter of every paragraph
  • apply a grey, italic style to quotations

Great! How do I do it?

First, create a Character Style which makes the results obvious. In the Character Style panel, press the New button, then double-click the new Character Style 1 to edit it. Set the name to “noticeable”, the font style to Bold and Character Color to red. Now we’ll easily see when our GREP styles will be applied.

The Character Style should look like this once set up.

The Character Style should look like this once set up.

Next, create a Paragraph Style which will apply the GREP styles. In the Paragraph Style dialog, press the New button, then double-click the new Paragraph Style 1 to edit it. Set the name to “GREPped”, and make sure Preview is enabled.

Normally, you would add GREP styles to the Paragraph Styles you wanted them to work in, but this is a good way to experiment. Press OK, then apply the GREPped style to a chunk of text in your document.

Apply that Paragraph Style!

Apply that Paragraph Style!

Set up the GREP

Double-click GREPped in the Paragraph Style panel to edit it, then choose GREP Style from the left side. Press the New GREP Style button. Under the Apply Style drop-down, choose “noticeable”, the Character Style dialog you made earlier. Right now, it’s applying to “\d+”, meaning “a digit, repeated one or more times”. As soon as you click away from the GREP Style you’re currently editing, any numbers in your text will turn bold red.

A selection of GREP styles all applied as part of a single Paragraph Style.

A selection of GREP styles all applied as part of a single Paragraph Style.

What about the other recipes above?

They’re easy enough to build using the drop-down menu on the right-hand side of the “To Text” field. These two are easy, just type them:

  • two spaces in a row
  • the name of your company 

These are a little harder:

  • four digits followed by an apostrophe followed by an s: \d\d\d\d’s
  • the first letter at the start of a paragraph: ^[\l\u]
  • at least 15 characters between quote marks: “...............+”

And here are the results of the style applied to some fake text.

And here are the results of the style applied to some fake text.

Conclusion

There’s much more to it, and of course Google is your friend if you want to know more about GREP. We might even write more about it in another article here. There are also some handy built-in GREP expressions in the Find/Replace dialog which you can repurpose into handy GREP styles. For now, know that GREP Styles can save a heap of work in the right circumstances. They’re great, they’re geeky, and that’s OK.

Comments (0)

You must be logged in to comment. Login Now

Feedback
Course Advisor
Don't Know Where To Start?
Ask A Course Advisor
Ask Us!
Copy the link below and paste it into an email, forum, or Facebook to share this with your friends.
Make money when you share our links
Become a macProVideo.com Affiliate!
The current affiliate rate is: 50%
Classes Start Next Week!
Live 8-week Online Certification Classes for: