Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
With its ability to find and replace character patterns in documents, GREP helps designers and editors work quickly and efficiently. Over the course of InDesign: 10 Things to Know About GREP, David Blatner demonstrates how to use GREP codes to improve workflow. He teaches GREP search techniques using patterns of numbers or letters or strings of words. David even shows how to use text patterns within a document. Exercise files accompany the course.
I want to find all the ordinal numbers in my document like 3rd or 4th and apply superscript formatting to that rd or the th after the number. Of course, I don't want to apply superscript to all the rd's and th's throughout my document. That would be crazy. Just the ones that follow the numbers. Well, can we do that? Sure, not a problem at all if we are using GREP styles. So I'll open my Paragraph Styles panel and I'm going to right-click or Ctrl-click with a one-button mouse on Body and then Edit "Body". I'll jump over to GREP Style, add a new GREP style and I'm going to apply a new style and I'm going to call this my ordinal superscript style and I'll come over and say this is going to be a Superscript Style, OpenType superscript.
I'll click OK and now I need to define what's going to get that superscript applied to it. Right now it's every digit in the document. Of course that's not what I want. What I want is th's or rd's and I put that vertical bar between the two and I'm going to put those in parenthesis just to kind of hold those together as a unit. Now again I don't want any rd or any th. I only want ones that are after a number and I don't want it to apply to the number as well. For example if I put a digit here, any digit then ordinal superscript would also apply to the digit.
Well that doesn't work. So when I delete that and instead I need to say to InDesign, "look behind these letters" and in fact that's the name of the GREP code. It's called a Positive Lookbehind and I could find that in the Add pop-up menu here. Down in the Match sub-menu there is this thing called a Positive Lookbehind. That means if there is something behind this text then go ahead and apply the style and if it's not there, then don't apply the style. You'll notice that there is also a Negative Lookbehind and a Positive Lookahead and I'll be looking at this one in just a minute. But in this case I'm going to use a Positive Lookbehind.
Now it's a little frustrating because the code is entered but the cursor does not end up where it needs to be for me to type what I'm looking for. Instead I need the cursor just one character to the left, in between the equal and the parenthesis, and here is where I need to tell InDesign what I'm looking for, what's behind the th or rd. And that's going to be a digit just in number. I am looking for any digit followed by a th or rd and when it finds this, apply the superscript to it. Let's click off here and I'll move this out of the way and we'll be able to see a in little tiny letters here. There is a th after 18.
I'll click OK, zoom in here so we can see it a little bit better, here we go, 18th. Now I can find more of them by pressing Command+F or Ctrl+F and open the Find/Change dialog box and I'll just look for any digit followed by a th, say. Click Find, it finds that one, find it again. There we go June 5th. So it automatically is applying the correct style to the th or rd but only after a number. Here we go, there is an rd 23rd, so it applied it correctly. Now what if I wanted to apply formatting to anything inside parenthesis, not the parenthesis themselves but only stuff inside parenthesis. Well again we can do that with GREP styles.
I'll edit my Body style and I'm going to go to the GREP style and I'll create another GREP style in this case I'm going to apply a new style. I'll just leave it Character Style 1, it doesn't matter but this one's going to be Myriad Regular and let's go ahead and apply a color to it so we can see it a little better, maybe this burgundy color. Click OK and we don't want it applied to digits. I'm going to apply this to anything in between parenthesis. So I'm going to start with my open parenthesis character and I know I'm going to ending with a closed parenthesis character and in between those I'm going to be finding pretty much anything. Let's say a wildcard, let's say Any Character, and I don't know what's going to be in there and I'm going to Repeat it let's say One or More Time(Shortest Match ). So just the stuff that's in between parenthesis, but the problem here is it this code finds the text inside the parenthesis and includes the parenthesis.
That's not what I wanted, what I wanted was only the stuff in between the parenthesis. I can do that with a Positive Lookbehind and a Positive Lookahead. So instead I'm going to delete this parenthesis and I'm going to use my flyout menu here. Let me go grab my flyout menu. That will place my cursor just the right place, just before all of that and say Match Positive Lookbehind and between equal and the parenthesis I'm going to put a backslash parenthesis. Remember that escapes the parenthesis character. So it's going to be the opening parenthesis is behind the text I'm looking for and now I need one more of these Match Positive Lookahead and in between the equal and the parenthesis I need to have a escaped closed parenthesis character. So one more time this means any character.+?, it's going to be any character with a shortest match in which behind it is a open parenthesis and after it is a closed parenthesis. Click off of it, Preview is on, so we can see that it worked.
It only found the stuff that was inside parenthesis. Of course, this doesn't have to be parenthesis, we could remove this and put let's say quote marks in instead. I'll put a double quote there and I come over here and put a double quote here and now it's just going to find stuff that's inside quotes. I don't see anything right now but no problem. I'll just come up here, let's say quote here and quote here and suddenly anything that's in between those quotes gets that Character Style applied to it, and it's totally on the fly, totally automatic and totally great.
So as soon as I close that quote mark, it applies the character formatting automatically for me and that is great. It is so much more efficient than having to find these things manually.
There are currently no FAQs about InDesign: 10 Things to Know About GREP.
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.