Video: 4. Escape characters

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.

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.

4. Escape characters

I would like to apply a special GREP Style to all the dollar amounts in mydocument. For example, down here in the lower left corner of this page I havegot some dollars here and dollars here. I would like to apply different kind offormatting 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 aNew GREP Style here.The new GREP Style is going to apply a character style called dollar amounts andwe'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 sayone or more digits and then period and then remember that if you can't recallthe 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 ormore digits, followed by a period, followed by two digits. And you think thatwould 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 GREPreserves 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 theparagraph. Well, we need to do what's called escaping it out. We need to tell GREPto stop thinking of this as a code and start thinking of it as a dollar signcharacter itself. And the way you do that is simply by placing a backslash infront 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, alsomeans something. We wanted to mean the actual period symbol. But GREP saysthe 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 forthe 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 characterstyle 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 aspecial code for any character and then I'll place a plus sign, which means oneor more of any characters, and then closed parenthesis. And the character styleI'm going to apply it to is, let's make a new one for stuff in parens and thisis going to be in different colors. Let's make it Beige and let's make itMyriad 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 rememberthat backslash trick, we can always just delete it and come out to the fly-outmenu 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 backslashparenthesis. There you go. Now that should work. Click off of it and we can seethat 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 beformatted differently then the rest of it. We can move it down by selecting itand clicking the down button. And now this comes second, so it overrides thestuff 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 tofind 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 andwhy don't I move this over so I can see both at the same time and I want totype that into this Find What: field, of the GREP tab of the Find/Change dialogbox. That's (a+b*c?). Well the problem here is these are all reservedcharacters, well not a, b and c but the rest of it is reserved characters. Sothat'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 itwere and the way you do that is before the phrase, I'm going to place thecursor just to the left of the parenthesis here and I'm going to do a \Q andthen at the end I do a \E and this is kind of undocumented. You are not goingto 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 andboom! it worked. Perfect! Great! It looked for that and ignored the reservedGREP 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 canmake when you are creating your GREP expressions. So whenever something failsand you are troubleshooting it and you are trying to figure it out, make sureyou look at each one of those characters and ask yourself, do I need to escapethat character or is it actually supposed to be a code?

There are currently no FAQs about InDesign: 10 Things to Know About GREP.

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.

Already a member ?

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

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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:

new course releases

newsletter

general communications

special notices

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:

new course releases

newsletter

general communications

special notices

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