Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using GREP styles

From: Creating Long Documents with InDesign

Video: Using GREP styles

InDesign has several ways of applying automatic character formatting to text, but none is more flexible or more powerful than GREP styles. With GREP styles you can apply styling based on patterns of text, not just the presence of individual characters like with nested styles. It's like having InDesign performing a never-ending Find/Change within a paragraph, and when it finds the pattern of text you are looking for it applies the formatting. If you're new to GREP, you're probably wondering where such a strange name came from. GREP is an acronym where the R and the E stand for regular expressions, and these are little bits of code that referred to patterns of text.

Using GREP styles

InDesign has several ways of applying automatic character formatting to text, but none is more flexible or more powerful than GREP styles. With GREP styles you can apply styling based on patterns of text, not just the presence of individual characters like with nested styles. It's like having InDesign performing a never-ending Find/Change within a paragraph, and when it finds the pattern of text you are looking for it applies the formatting. If you're new to GREP, you're probably wondering where such a strange name came from. GREP is an acronym where the R and the E stand for regular expressions, and these are little bits of code that referred to patterns of text.

InDesign can use these codes to perform Find/Changes on the text, and you can also perform this kind of operation manually in the Find/Change dialog box. But in paragraph styles you can set it up once and have it applied to all the documents that use this style throughout your workflow. I should also say that regular expressions and GREP are a very deep topic and that I'll just be showing a very small part of it here. Okay, in this first example I have several years that I would like to appear in a different character style. I have them over here in parentheses and some are not in parentheses, and I'm going to try to use a GREP style to accomplish this.

First of all, setup a character style here, so I have Numbers character style and in my Paragraph styles I'll right- click on the style that all this text is set in Story to edit it, and I'll go to GREP Style and click on New GREP Style. Under Apply Style I want to pick my Numbers character style, and then I have to enter in a regular expression to tell InDesign what to look for. And by default I have this \d+. Backslash d is a regular expression for a digit, and the plus means one or more times, and if I click off of that the style will be applied immediately because I have Preview checked.

So I'll click off, and sure enough the years now have the character style applied inside the parentheses, outside the parentheses. But if I click OK, I can see that InDesign did almost too good a job. It found all the other numbers as well, so not just years, but any digits. So, the 24th of November, 8d, so on and so forth, all the numbers are found and they now have the character style applied to them. So I need to limit the scope a little bit. So, I'll right-click on Story again and choose Edit S-Story, and back to my GREP style.

So now I just want to try to do the years and the parentheses. Okay, so first of all I have to figure out how am I going to do these parentheses? So I'll eliminate this expression. First thing I need is the open parenthesis character. Now in regular expression, parentheses are reserved for certain functions to apply inside GREP, so you can't just type in open and closed parentheses. You have to do something called escape it. You can escape it by typing a backslash character before the character. So I could type \(, which will give me an open parenthesis, or if you can't remember that you can just choose it from the pop-up menu by choosing Symbols > open parenthesis Character.

So now I have open parenthesis, now I want to find a sequence of four digits. So remember \d is one digit, but now I want exactly four times, and the way I tell InDesign to look for a specific number of things is to put it in these curly braces. So, open and close curly braces and then inside that I tell it the number of times I want it to find that, so I want 4 digits. So far open parenthesis, a digit, four times, and now I need the close parenthesis character.

Again, I can just escape it with the backslash character, so \), or I could pick it again from the Symbols menu. Symbols > close parenthesis Character. I'll click off, and I can see that it found exactly what I wanted. All right, that's an interesting example, but let's see if we can try something a little more flexible. Like what if I wanted to find anything inside parentheses, in addition to the years I have strings of text inside parentheses that are of different lengths.

What if I wanted to apply the character style to those? You might think you can use the same idea that we saw with the digits and just replace them with a wildcard, like one or more characters, and we can try that. I'll go inside the expression and I'll replace this with the wildcards for one or more characters. A character is just represented by a period inside the GREP expression, and one or more times is represented by a plus. So open parenthesis, one or more characters, close parenthesis and I'll click off, and I'll click OK and I can see that InDesign has done really too good a job here.

It's found the first open parenthesis, and then it keeps going on and on applying the character style all the way until it finds the last close parenthesis within a paragraph, and that's way too much stuff. I wanted it to stop when it found that first close parenthesis over here. All right, so I need to edit that GREP expression. I'll right-click on the Paragraph style, go back to GREP Style and what I need to do is to tell it to look for something that's not a close parenthesis, so the first time it finds a close parenthesis it has to stop applying that GREP style.

So I go inside of the expression and I eliminate my wildcard, and then I'll tell it to look for a group of things. The way I tell it to look for a group is with the square brackets and inside the square brackets I'm going to tell it to look for a not close parenthesis. Not is represented by caret, and then I can just type the close parenthesis. Now, I want one or more of these because I don't know how long the expression will be inside the parentheses. I have different lengths of text. So the wildcard for one or more is plus.

So open parenthesis, anything that's not a close parenthesis, one or more times and then finally that close parenthesis. I'll click off and click OK, and there I can see it worked. So it had to stop when it found the first close parenthesis each time. GREP styles are really interesting and powerful. They're one of my all-time favorite features in InDesign, but they're certainly not the easiest feature in the world to learn. If you want to know more about regular expressions, I really recommend you check out Kevin Skoglund's course on Using Regular Expressions.

Show transcript

This video is part of

Image for Creating Long Documents with InDesign
Creating Long Documents with InDesign

59 video lessons · 15858 viewers

Mike Rankin
Author

 
Expand all | Collapse all
  1. 10m 48s
    1. Welcome
      54s
    2. Using the exercise files and scripts
      1m 51s
    3. Long-document workflow overview
      4m 20s
    4. Analyzing the planned output
      3m 43s
  2. 34m 7s
    1. Using master pages
      9m 34s
    2. Using layers
      7m 23s
    3. Using text variables
      6m 42s
    4. Using section markers
      5m 44s
    5. Synchronizing text
      4m 44s
  3. 26m 16s
    1. Using InDesign templates
      7m 10s
    2. Setting up preferences
      3m 27s
    3. Using Word templates
      5m 50s
    4. InCopy workflows
      5m 17s
    5. Creating a production manual
      4m 32s
  4. 40m 2s
    1. Using Based On styles
      6m 14s
    2. Using nested styles
      5m 56s
    3. Using Next Style
      3m 39s
    4. Using GREP styles
      6m 17s
    5. Using object styles
      2m 48s
    6. Using table and cell styles
      5m 8s
    7. Using swatches
      5m 33s
    8. Using Quick Apply
      4m 27s
  5. 37m 57s
    1. Placing text
      4m 57s
    2. Placing images
      3m 41s
    3. Creating metadata captions
      4m 3s
    4. Using Mini Bridge
      4m 38s
    5. Using libraries and snippets
      6m 4s
    6. Using GREP Find/Change
      5m 5s
    7. Find/Change tips
      5m 21s
    8. Using Layout Adjustment
      4m 8s
  6. 15m 53s
    1. Using Notes
      4m 7s
    2. Tracking changes
      4m 36s
    3. Using CS Review
      7m 10s
  7. 34m 43s
    1. Creating tables of contents
      7m 9s
    2. Alternative uses for the TOC feature
      4m 9s
    3. Creating cross-references
      6m 8s
    4. Creating footnotes
      6m 31s
    5. Importing footnotes
      6m 47s
    6. Creating endnotes
      3m 59s
  8. 33m 50s
    1. Scoping out the index
      2m 19s
    2. Creating index topics and references
      9m 29s
    3. Creating index cross-references
      3m 1s
    4. Creating index references with Find/Change
      3m 31s
    5. Generating an index
      3m 35s
    6. Preserving formatting in an index
      5m 13s
    7. Using third-party indexing tools
      6m 42s
  9. 26m 44s
    1. Using InDesign book files
      4m 37s
    2. Numbering book documents
      5m 46s
    3. Synchronizing book documents
      7m 5s
    4. Preflighting book documents
      3m 49s
    5. Outputting book documents
      5m 27s
  10. 12m 54s
    1. Using conditional text
      5m 1s
    2. Using Smart Text Reflow
      4m 3s
    3. Using object styles for customization
      3m 50s
  11. 25m 17s
    1. Preflighting documents
      6m 56s
    2. Exporting to print PDF
      5m 26s
    3. Exporting to interactive PDF
      5m 36s
    4. Archiving a project
      7m 19s
  12. 48s
    1. Goodbye
      48s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Creating Long Documents with InDesign.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.