Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
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.
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.
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.