Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
119 Video lessons · 50993 Viewers
117 Video lessons · 38762 Viewers
113 Video lessons · 81590 Viewers
65 Video lessons · 11666 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.