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

5. Finding how many and how long

From: InDesign: 10 Things to Know About GREP

Video: 5. Finding how many and how long

I want to find the word chocolate or chocolates. Either chocolate singular or chocolates plural. So I'll open up the Find/Change dialog box with a Command+F or Ctrl+F on Windows, and if I would just search in for chocolate by itself I could do that in the Text tab of the Find/Change dialog box. But in this case I'm going to be typing a pattern in. So I'm going to use the GREP tab instead. So I'll type Chocolate and then I want to say sometimes it has an S on the end, and I don't know which one it's going to be. So I need to tell InDesign with some kind of special code that the S may or may not be there.

5. Finding how many and how long

I want to find the word chocolate or chocolates. Either chocolate singular or chocolates plural. So I'll open up the Find/Change dialog box with a Command+F or Ctrl+F on Windows, and if I would just search in for chocolate by itself I could do that in the Text tab of the Find/Change dialog box. But in this case I'm going to be typing a pattern in. So I'm going to use the GREP tab instead. So I'll type Chocolate and then I want to say sometimes it has an S on the end, and I don't know which one it's going to be. So I need to tell InDesign with some kind of special code that the S may or may not be there.

Now the code I'm going to find inside the @ sign fly-out menu. I'll come down here to Repeat and I'm going to say this is going to Repeat Zero or One Time. This Zero or One Time code, which if I selected you can see is a question mark, is a great way to find words or phrases when a single letter may or may not be there. In this case it will find Chocolate and then the S could be there or could not be there. Now let's go ahead and come out here, I'm just going to click out here and zoom into 200% view so we can see whatever the results are, little bit better, click Find, and there we go. Chocolate it founded, click again chocolate, chocolate, this is pretty good, oh, it's finding lots of chocolate, I like chocolate. I'm just going to keep clicking on here until it proves the point that indeed it will find chocolates as well. There we go, chocolates, Bliss no.5 Chocolates. So it found one or the other.

Now remember that it's only finding because it's case-sensitive. So only uppercase C and then Chocolates. If I wanted to find both uppercase or lowercase I would have to type-in a different code. Lowercase or uppercase inside square brackets, let's go ahead and try that. And I'm just going to keep clicking Find, oops, there we go. There is a CHOCOLATE. Now it looks like it's all uppercase when here it's lowercase. What's going on there? Well, I can see if I look up in the control panel here that the All Caps formatting is applied to this. So this text must actually be or behind the scenes lowercase, but the all caps is making it look like it's uppercase.

Here is another example of when that question mark code might be useful. Maybe I have the word color in my document, but sometimes it's the Brit spelling with a U. I put a question mark after it and now it will find both color with a U or without a U. It could go either way very, very useful to sort of expand the options of what this will find. I don't actually have the word color in here so I'm not going to search for that, instead I'm going to search for a different code, I'm going to search for everything in parenthesis. But in this case I'm going to zoom back here and go to a particular page where I know there is going to be a problem. There is always a problem in here.

I am going to go to page 8 here and zoom into 200%, and I can see that this paragraph has two different sets of parenthesis. So why is that important? Well, I'll move that out of the way a little bit. I'll open my Paragraph Styles and I'm going to Edit my Body text style here, and I'm going to edit it with a GREP Style. I am going to add a GREP Style here, how about we set this for -- just make a new one, it will be easier, and I'll say this is going to be Myriad Pro, Regular, let's change its color so it really stands out here, Beige color, click OK, and it's going to be everything that is within a parenthesis.

So I'll say open parenthesis, and then pretty much everything that shows up between that and the closed parenthesis. I'll just type that backslash parenthesis, /), click off here we can see that it kind of worked and kind of didn't. It applied it to this phrase in here inside these parenthesis but then it just kept on going, kept on going, kept on going until this one. Well, this is an issue with GREP. GREP is what's called greedy. It will always grab as much as it can within a paragraph. Now if you wanted to be less greedy, if you wanted to just choose the shortest match that it can get in here you need to choose a different code, and it shows up there in the Repeat fly-out menu, let's go and take a look, it's good thing that the Paragraph Styles Options dialog box is still open, I had the Preview on.

So I don't even have to go back to edit it, I simply click on here again. So I'm going edit this code so that it is less greedy, and the key here is instead of that little plus sign there I'll delete that, I'm going to say find me everything, the dot means find everything, any kind of character, but not Repeat One of More Times like I was using instead I'm going to use it One or More Times (Shortest Match). That Shortest Match is very, very important in this kind of circumstance, and the code is +?. So that means grab any characters, the string of characters, but keep it the shortest match possible before the final parenthesis. I'll click off here and you can see that now it's working perfectly. It's applying it to this phrase inside the parenthesis, and this one, but not the text in between.

Okay, one more quick repeat trick that you might want to use. I'll choose a New GREP Style here, and I'm going to make a new style which is going to be just for my years, anything that looks like a year, four digits in my document. Why don't I just go ahead and change this. I'll just change the color to something bright, so we can really see it like Magenta, click OK, and it's going to be not a string of digits of any length instead it's going to be only four digits long. Only find me four digit long characters with no other characters in between like no commas or anything. The way you do that is you do it {4}, and that means find a string of four any digits. Any digits, but only four of them in a row. And that's a little undocumented trick. It's certainly documented in GREP documentation but not in InDesign. I mean there is nothing inside this fly-out menu that would indicate that you can do this kind of code. That's one of those things that you just have to know how it works.

I will click OK. I'm just going to go find that in the text itself, and if I don't find one I better just go ahead and type one. So I'll just come in here and say 2009 and as soon as I finish four digits in a row it applies the GREP style to it. When you are typing out a GREP code it's imperative that you have absolute precision when you are defining the pattern you are looking for. These Repeat codes like the Zero or One Time or the One or More Times really help you to find that pattern so you find exactly what you are looking for.

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 · 6346 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.