Viewers: in countries Watching now:
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 would like to apply a special GREP Style to all the dollar amounts in my document. For example, down here in the lower left corner of this page I have got some dollars here and dollars here. I would like to apply different kind of formatting to that. So I'm going to go to the Paragraph Styles panel and I'm going to double-click on this. Just so it selects it, I see this is Body text, so I'll right-click on it or Ctrl+Click with one button mouse and say I want a New GREP Style here. The new GREP Style is going to apply a character style called dollar amounts and we'll change the color just so that's a easy way to really stand out, you can see that it is different and it's going to apply it not just to the numbers.
Right now it's just the numbers, but I want to apply it to the entire dollar amount. So how would I do that? Well, you might think that you could do something like dollar sign, let's say one or more digits and then period and then remember that if you can't recall the codes for things like digits, you can always pull them out of these fly-out menus and then pull things out of like Wildcard > Any Digit. So, easy to do it there as well. So one or more digits here, in fact this case is just two digits. So one or more digits, followed by a period, followed by two digits. And you think that would work, but it doesn't. In fact, if I click off here in the blank area, you can see that it completely fails.
Now, none of the digits are being found at all. Why? Well, the problem is GREP reserves certain characters for its special codes. For example the dollar sign. The dollar sign means something to GREP. So GREP looks that and says, well, the dollar sign means end of a paragraph. Well, we don't want it to mean end of the paragraph. Well, we need to do what's called escaping it out. We need to tell GREP to stop thinking of this as a code and start thinking of it as a dollar sign character itself. And the way you do that is simply by placing a backslash in front of it. So we can do \$ and GREP says, oh you mean the real dollar sign.
Okay, I got it. So \$, \d, which is the code for digit and then that dot here, the period, also means something. We wanted to mean the actual period symbol. But GREP says the dot means any character. Any character, it doesn't matter what it is. It's looking for any character and that's a problem. So we need to escape it out. Once again, just put a backslash in front it. So it makes it a little bit ugly, \$, \d and so on. But that is the code for the dollar value itself. I'll deselect here, and we can see that the code worked.
Because the Preview checkbox is on, we can immediately see that that character style was applied to the full dollar amount. Let's try another one. I'm going to create a New GREP Style and this case I'm going to create a New GREP Style for anything inside of parenthesis. So I'll type open parenthesis and then dot which means any character, right. That's a special code for any character and then I'll place a plus sign, which means one or more of any characters, and then closed parenthesis. And the character style I'm going to apply it to is, let's make a new one for stuff in parens and this is going to be in different colors. Let's make it Beige and let's make it Myriad something like that, click OK and we can see that, oh my goodness, what happened? All the text got changed.
Well once again, we have a problem because of special reserved characters. The parenthesis is a reserved character. So we need to escape it out. How do we do it? Well, we could just put a backslash in front of it or if we don't remember that backslash trick, we can always just delete it and come out to the fly-out menu and look for the symbol here and right inside the Symbols fly-out menu, we can see closed parenthesis character. There we go. And all it is, is backslash parenthesis. There you go. Now that should work. Click off of it and we can see that all the stuff in parens including the parens gets that applied to it.
Because this GREP Style comes after this GREP Style, it overrides it. So it goes down the list in order. If we want the dollar amounts to be formatted differently then the rest of it. We can move it down by selecting it and clicking the down button. And now this comes second, so it overrides the stuff in paren style. I'll show you one other example of the Escape feature. Let's zoom out here and I'm going to use Shift+Page Up to come back to page 5 here. And then why don't I zoom in on just this text so we can see that? I'll just select it and then Command+4 or Ctrl+4 on Windows, just to zoom into 400% and I can see that I have got a really wacky bit of text there and I want to find that kind of text using GREP for some reason.
So I could open the Find/Change dialog box, Command+F or Ctrl+F on Windows and why don't I move this over so I can see both at the same time and I want to type that into this Find What: field, of the GREP tab of the Find/Change dialog box. That's (a+b*c?). Well the problem here is these are all reserved characters, well not a, b and c but the rest of it is reserved characters. So that's is going to cause me all kinds of grief. Fortunately, GREP has a way to escape out a whole clause, a whole phrase as it were and the way you do that is before the phrase, I'm going to place the cursor just to the left of the parenthesis here and I'm going to do a \Q and then at the end I do a \E and this is kind of undocumented. You are not going to find this one in this fly-out as far as I know. I don't think it's hiding in there, but that means escape out all of this phrase and find exactly that.
Let's try it out. I'll make sure my cursor is up here and then I say Find and boom! it worked. Perfect! Great! It looked for that and ignored the reserved GREP Codes in there because I escaped those characters with the Q and the E. Forgetting to escape characters is one of the common mistakes that you can make when you are creating your GREP expressions. So whenever something fails and you are troubleshooting it and you are trying to figure it out, make sure you look at each one of those characters and ask yourself, do I need to escape that character or is it actually supposed to be a code?
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.