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

2. Using GREP in the Find/Change dialog box

From: InDesign: 10 Things to Know About GREP

Video: 2. Using GREP in the Find/Change dialog box

Now let's go a little bit deeper into GREP, creating a more complicated expression. I'll open up the Find/ Change dialog box by pressing Command+F or Ctrl+F on Windows and I'm going to jump over to the GREP tab by pressing Command+2 or Ctrl+2 on Windows. Always make sure you're in the GREP tab if you're going to be typing GREP character codes. I am going to be filling in both the Find What and the Change To fields. But before I do that, I want to take a look at the Query pop-up menu and this is whole bunch of preset Find/Change queries that Adobe has given us. The ones at the top are regular text Find/ Change queries, the ones at the bottom are object queries and the ones in the middle are GREP Find/Change expressions.

2. Using GREP in the Find/Change dialog box

Now let's go a little bit deeper into GREP, creating a more complicated expression. I'll open up the Find/ Change dialog box by pressing Command+F or Ctrl+F on Windows and I'm going to jump over to the GREP tab by pressing Command+2 or Ctrl+2 on Windows. Always make sure you're in the GREP tab if you're going to be typing GREP character codes. I am going to be filling in both the Find What and the Change To fields. But before I do that, I want to take a look at the Query pop-up menu and this is whole bunch of preset Find/Change queries that Adobe has given us. The ones at the top are regular text Find/ Change queries, the ones at the bottom are object queries and the ones in the middle are GREP Find/Change expressions.

For example if I choose this Dash to En-dash, I can see a really long set of codes in here. In fact it's long I can't even see all of the codes. So I'll show you little trick. I'll hover my cursor over the field and it shows me the entire expression. Well, what is going on there? I don't need to get into all the details here. But what this means is find a space character. It could be any kind of space character. A regular space or an Em space or a hair space. That's what all these codes are. All the different kinds of spaces that InDesign knows about, followed by a hyphen, a dash, followed by another one of those spaces. That's what's really going on there. And it's finding all of those things and it's changing it to this little code here, which means space followed by a regular en-dash followed by a space. That's all that means. It normalizes all of those different space dash spaces into just the space en-dash space.

All right. So that's one of the ones that Adobe gave us. Let's look at another one then here. How about Remove Trailing Whitespace? This is a little simpler, \s means any whitespace. So that could be a space character or a tab character or a return, anything that's just whitespace and then one or more of them. That little plus there means one or more of the previous character. So one or more whitespace characters and then what's this dollar sign? Well I'm going to be talking about location codes a little bit later on in quite some depth, but I'll just tell you know, I'll give you a little hint.

That means at the end of a paragraph. So this is one or more white spaces at the end of a paragraph. And because Find What is filled in and Change To is empty and the Find Format and Change Format fields are empty as well, that means it's going to search for all of these white spaces and if I hit Change All, it's going to delete them all. So it deletes all of the whitespaces at the end of a paragraph. Let's try it out. I'll click Find and it jumps right over to this one. There is a whitespace there, I better say Change/Find and Change/Find. And you could see it's just removing all of these things. I can't even see all of these. Let's zoom in here to 200% and I'll turn on Type > Show Hidden Characters, there we go. I can actually see the little dot there, the green dot means that it's a regular space there at the end of the paragraph.

So I'll say Find it. Yep, there it is. Change then find, change then find. It's finding all of those whitespaces and removing them. It could be 1 or 15 or 100 spaces in a row. It doesn't matter. It will find all of them. In fact this code will even find multiple returns. I just place the cursor at the end of that paragraph and hit Return or Enter a couple of times to move down. So I have these blank paragraphs down here and this code will find that as well. Let's try it out. I'll place my cursor above the text, click Find.

There it goes. It found it. I can't see everything on my screen here but it did find it. It found all of those. In fact if I click Change All, it will go through my entire document and it will delete all of them including those blank lines. Well that may be what you want. Maybe that's exactly what you want and that's great or maybe it's not what you want. You wanted it remove the spaces and tabs at the end but you did not want it to remove the blank returns. If that's the case, well we better massage our code a little bit. So I'm going to undo that with a Command +Z or a Ctrl+Z on Windows and I'll come in here and change the code. I'll delete the Any Space character, this wild card, and I'm going to instead tell it exactly which kind of spaces I want it to look for. So I'm going to put it inside of a square bracket. So I have an open square bracket and I'm going to say find me any, let's say tab.

How do I type the tab code? I don't know. But it's easy to pull it out of that little @ sign flyout menu here. Tab, oh, there it is. It's \t. So it typed it for me. Then maybe I want just any regular space. So I'll just type the space on the spacebar on the keyboard and that typed that kind of space and then maybe we want some other kind of spaces as well. I'll come out here to the White Space pop-up men in the @ sign flyout menu here and I'll say let's find any em-space as well. Then I'm going to close that expression with a close square bracket.

So it's tab or a regular space or an em- space, and I want one or more of them, so my plus sign is there, and I only want it at the end of the paragraph and that's why that dollar sign is. Now when I say Change All, it will go to the entire document, 21 replacements made, click OK and it removed all of them but it did not find or replace my blank returns. Okay one last thing that we're going to search for here, let me pan down to this e-mail address. I want to find e- mail addresses in my document. So how am I going to do that? Well I need a new code. So I'll go ahead and delete that one and I'm going to start building my code for e-mail addresses. This is really exactly how I build these codes. I don't memorize the whole thing; I build it piece by piece.

So I'm going to start with an @ sign because I know all my addresses have an @ sign in them. Now on the right side of my @ sign I know that I want characters because I know it's going to be lowercase or uppercase characters. So I'll find my wild card that is Any Letter. There we go. Any lowercase or uppercase character and I know that I want one or more of them. Not just one character but I want it to repeat it one or more times. I also happen to know that there's a 5 in here. So I need a digit as well. Lowercase character, uppercase character, or I'll click just after the u there.

I need a wild card for any digit. That's a \d. So now I found any lowercase uppercase or digit, one or more of them after the @ sign, and what about before the @ sign? Well that's easy. I can select all of that, copy it with Command+C or Ctrl+C on Windows, click before the @ sign and Command or Ctrl+V to paste it in here. So now I'm searching for some text, some words, @ sign and then another text or word. Let's try it out. I'll place my cursor up here, click Find. Uh-oh! It didn't get the whole e-mail address. It got the text before it and the @ sign and this but it didn't get the .com. Why? Well you see always making mistakes. You always have to look at it and troubleshoot the GREP code. I can see that - Oh! You know what? It's searching lowercase, uppercase or digits but it's not finding this little dot, the period there. So I better type the period. Because it's inside the square brackets I can just type the period on my keyboard before and after it because there might be a period before it as well.

That is going to be a pretty robust GREP code for finding my e-mail addresses. Maybe there would be hyphen, I don't know, maybe there is underscores. I could add those to my expression as well. But for right now in this document I'll keep that relatively simple here and see if this works. Let's say Find it. Yep, there we go, it found the entire e-mail address. Well now once I've found it, what am I going to do with it? Well I would like to apply formatting to it. I'm not going to change the e-mail address, I'm just going to apply formatting to it. So I'm going to do that by clicking down here in the Change Format field, and when we're inside this field, we'll open the Change Format settings dialog box and I'm going to apply a character style to it.

So my character style is going to be my e-mail style. I don't see one here. So I'll go ahead and make a new one. This is one of my favorite new features in InDesign CS4, the ability to create a new character style without having to close the dialog box then come back to it later. Just pull it right out of that pop-up menu and this is going to be my e-mail style and I'm going to change the font let's say I'll make it Myriad and I'll change the color so it'll be more obvious on screen here. Why don't we make it this kind of burgundy color? So it will fill with a burgundy color.

Click OK, click OK. So now I can see that I have a code in the Find What field but nothing in the Change To field. Does that mean it's going to delete the e-mail address? No. Because I have chosen something in the Change Format field. So when I have something in Find What and something in Change Format, but nothing in Change To, it means don't change it, ignore it. Don't change the words at all, just apply formatting to it. Let's try it out. I'm going to click Change All and it went through my whole document, it made the re-replacements and you can see that it changed all my e-mail addresses into this character style.

Okay the last thing I'm going to do here is save my Find/Change query. Because if you've spent more than 30 seconds on one of these GREP codes, you should save it. I mean you're probably going to want to use it again later. So to save this, just go ahead and click this little disc icon and it saves it to disc. I'll call this my format e-mail addresses. Click OK and now that shows up in my Query pop-up menu as well.

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