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

4. Escape characters

From: InDesign: 10 Things to Know About GREP

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.

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.

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?

Show transcript

This video is part of

Image for InDesign: 10 Things to Know About GREP
InDesign: 10 Things to Know About GREP

12 video lessons · 6383 viewers

David Blatner
Author

 

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.

Join now "Already a member? Log in

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 InDesign: 10 Things to Know About GREP.

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 preferencesfrom 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.