InDesign: 10 Things to Know About GREP

InDesign: 10 Things to Know About GREP

with David Blatner

 


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.
Topics include:
  • Using pre-built find/change expressions
  • Reordering names in an exported list from a database
  • Working with GREP and fonts
  • Establishing character formats with GREP style
  • Using escape characters to customize code
  • Accessing the fly-out menus to specify search commands
  • Applying global conditions using GREP

show more

author
David Blatner
subject
Design
software
InDesign CS4, CS5, CS5.5, CS6
level
Intermediate
duration
1h 8m
released
Apr 30, 2009

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(Music playing.)
00:04GREP makes formatting or editing large amounts of text easy. So what is GREP?
00:09It's a way to describe patterns in text. For example you can use any old Find
00:14feature to search for the word dog, but it takes GREP to search for say any
00:19word that starts with a d and ends with a g. That's a simple pattern.
00:24Now I'm David Blatner and this is InDesign CS4: 10 Things To Know About GREP.
00:30In this title we're going to look at how you can use InDesign's Find/Change
00:33dialog box to search for complex patterns, like any four-digit number with or
00:39without a comma in it but only at the start of a paragraph.
00:42Then we'll explore GREP styles and how you can use them to apply formatting to
00:46a text pattern like any string of words that are inside parenthesis. I'll even
00:51show you how you can reorder names in a list exported from a database.
00:56Patterns of text. That is what GREP is all about and the more text you have
01:00the more you need GREP. If you create one-page ads, this title is handy but
01:05it's not critical. But if you layout books or newspapers or catalogs, these are
01:1110 things you need to know about GREP. Let's jump in.
Collapse this transcript
1. Ten Things to Know About GREP
1. GREP basics: Using codes to find text
00:05So GREP is all about finding patterns of text and you're already familiar with
00:09patterns of text. Like what's a bunch of letters all grouped together?
00:12Well, that's a word, right? Or what's a bunch of words all grouped together. Well,
00:16that's a sentence or maybe a paragraph.
00:19But you can't say to InDesign, find me a bunch of words all grouped together.
00:23Now you need to type in codes, GREP codes. That's what InDesign is expecting.
00:27So the good news is that those codes are either really simple or InDesign will
00:32actually type them for you.
00:34Now because we're searching for text the best place to go and do that is the
00:39Find/Change dialog box. I'll open the Find/Change dialog box by pressing
00:43Command+F or Ctrl+F on Windows and we'll see that there are actually four
00:47different dialog boxes in one here: Text, GREP, Glyph and Object. We're going
00:52to be focusing not on text, which is where most people do their work but
00:55instead on GREP.
00:57So I'll click on GREP or you can press Command+2 or Ctrl+2 on Windows to jump
01:01to that second tab and I'm going to type my code into the Find What field.
01:06So I'm going to search for some kinds of chocolate. Let's say I'll search for a
01:10Milk chocolate and I'll click Find and it will jump right to the first instance
01:16of Milk chocolate. Let's see where is that, there it is, right in the text here.
01:19And I zoom in to 200% here. I'll click on the document and then go into
01:24200% with a Command+2 or Ctrl+2 on Windows, and there is the text that I found
01:29Milk chocolate.
01:30But in this case I want to find Milk chocolate or maybe Dark chocolate, one or
01:36the other. So let's go ahead and type in some codes for that. I'm going to type
01:41Dark here at the beginning and I want to tell InDesign to search for either
01:45Dark or Milk chocolate. So I'm going to add a vertical bar. On the US keyboard
01:50that's Shift+\, gets that vertical bar in between them. And I also need to put
01:55some parenthesis around this. So it's going to be Dark or Milk chocolate.
02:00That's our first code. Let's go and try it out. Find that and it finds Milk
02:05chocolate, Find again and it says it's completed.
02:08Well I know there are some other instances of Dark chocolate and Milk chocolate
02:11in this document; it's a whole magazine about chocolate after all. So I need to
02:15find out why it's not working. So here is the key. GREP is case-sensitive.
02:20You always have to pay attention to the case of every character. So in this case
02:24it's looking for D, M and c, but if change that to a C and hit Find,
02:32now it will find it. It will find Milk Chocolate, click Find again, there is Milk
02:36Chocolate and there is Dark Chocolate. So it will find either Dark or Milk Chocolate.
02:40Now if I want to tell that GREP code to search for lowercase or uppercase,
02:45I need to add a few more codes in here. So I'm going to put in some more
02:49characters. This is going to be either lowercase or uppercase d. Did you see that?
02:54I put in an open parenthesis and then a lowercase and then a vertical
02:58pipe and an uppercase d and then closed parenthesis, and I'll do the same thing
03:02here for the m, lowercase or uppercase m. And I'll do the same thing for the c.
03:07This is little bit more verbose than you need to be. There is more codes in
03:11here than you actually need, but it's a very easy way to see what's going on.
03:15Dark chocolate, lowercase or uppercase, lowercase m or uppercase and lowercase
03:20or uppercase c.
03:21So now we have a lot of flexibility in here. It's going to be looking for Dark
03:24or Milk chocolate in uppercase or lowercase characters. Let's try it out.
03:29Find it, find it, find it. There we go. It's going to keep looking around and there we go.
03:33There is the Dark chocolate in lowercase. Both d and c are in lowercase here as well.
03:39I want to point out one little trick here that I need to warn you about.
03:42If I use the Option+Spacebar or Alt+Spacebar trick to use my grabber hand to try and
03:48scroll this over, I'm going to have a problem and that problem is that my GREP
03:53code will disappear. This always catches me. It's very, very frustrating.
03:57For example I'll do Option+Spacebar and I'll start to be able to scroll around,
04:01but look what happened to my GREP code. It completely disappeared. That is very
04:05frustrating. Maybe it's a bug in InDesign, I don't know. But it actually typed
04:09a bunch of spaces here because the GREP code was selected. Fortunately there is
04:14a way to get those codes back.
04:15So if I click on this little pop-up menu with the double arrows, I can see all
04:19of the previous Find/Change routines that I've done. In this case the Dark
04:23chocolate and Milk chocolate, GREP that I was choosing. So I'll just load it
04:27back in there. Very, very easy to get that back into the Find/Change dialog box.
04:31Just something to watch out for.
04:33Okay. Now it's time to do a little bit more complex GREP expression. I'm going
04:37to find all the words in my document that start with a letter c and end with e.
04:42So I'll type c in here and I'll type e here. But what's going to go in between the two?
04:47I'll click my cursor right between the c and the e. What's going to go
04:51in between there? Well, I need to type some codes that mean 'Find me some more
04:55characters.' I don't know what those codes are necessarily but the good news is
05:00that InDesign will type them for me.
05:02I'll go over to this @ sign flyout menu and I'm going to choose a wild card or
05:06a meta character. The wild card that I'm going to choose is Any Letter.
05:11So I'll choose that and you can see that it types some codes for me.
05:14It did a square bracket, \l\u, and then closed square bracket.
05:20Well what does this mean? I'll tell you. It means a lowercase character or an
05:24uppercase character and because it's in square brackets it means one or the
05:28other of these. This is another way to do a this or that. In GREP there are
05:33multiple ways of doing the same thing.
05:34But in this case it's only going to find three letter words that's start with c
05:37and end with e. We want it to be a four-letter or five-letter or eight-letter word
05:41or whatever. So we need to type one more code in here, a repeat code.
05:46So I'll go back to the flyout menu here and go to the Repeat submenu and
05:51I'm going to be going into much more detail about the Repeat submenu later on.
05:55But for right now I'm just going to tell you I'm going to choose One or More
05:58Times and that types in a little + code here. So now we have a code that says
06:03start with a c, then I want to have a string of one or more lower or upper case
06:08characters and then end with an e.
06:10Now I'm going to tweak this code one more way. I want that to be lowercase or uppercase c.
06:16So I'll go ahead and type that square bracket, cC, closed square bracket, and again, this is just
06:24a different way of doing the same kind of this or that that we saw earlier. c or
06:29C followed by lower or uppercase characters, one or more of them and then ending with an e.
06:34All right let's try it out and see if it works. Find. There it goes. It found a
06:39word that starts with a c and ends with e. Find the next and this is great
06:43because it was also lowercase or uppercase. Remember? So it found that
06:47chocolate as well. Find Next, Find Next, Find Next. And I can just keep finding
06:51them until it finds this word, look at that. It even found coffee because
06:56coffee starts with c and ends with e.
06:58Now there is one more thing I need to tell you about GREP codes and that is
07:02you are going to make mistakes. Everybody makes mistakes when doing GREP.
07:06I'm making mistakes while working on this title right now. In fact, if you're not
07:09seeing my mistakes, it's because the editors cut them out, but everyone makes mistakes,
07:14and that's okay. That's what undo is for. Just undo, Command+Z or
07:18Ctrl+Z on Windows and then look at your codes again carefully and then try it again.
Collapse this transcript
2. Using GREP in the Find/Change dialog box
00:02Now let's go a little bit deeper into GREP, creating a more complicated
00:05expression. I'll open up the Find/ Change dialog box by pressing Command+F or
00:09Ctrl+F on Windows and I'm going to jump over to the GREP tab by pressing
00:14Command+2 or Ctrl+2 on Windows. Always make sure you're in the GREP tab if
00:18you're going to be typing GREP character codes.
00:20I am going to be filling in both the Find What and the Change To fields.
00:25But before I do that, I want to take a look at the Query pop-up menu and this is
00:29whole bunch of preset Find/Change queries that Adobe has given us. The ones
00:34at the top are regular text Find/ Change queries, the ones at the bottom are
00:37object queries and the ones in the middle are GREP Find/Change expressions.
00:42For example if I choose this Dash to En-dash, I can see a really long set of
00:46codes in here. In fact it's long I can't even see all of the codes.
00:50So I'll show you little trick. I'll hover my cursor over the field and it shows me the
00:55entire expression. Well, what is going on there? I don't need to get into all
00:59the details here. But what this means is find a space character. It could be
01:03any kind of space character. A regular space or an Em space or a hair space.
01:08That's what all these codes are.
01:10All the different kinds of spaces that InDesign knows about, followed by a
01:13hyphen, a dash, followed by another one of those spaces. That's what's really
01:17going on there. And it's finding all of those things and it's changing it to
01:21this little code here, which means space followed by a regular en-dash followed
01:26by a space. That's all that means. It normalizes all of those different space
01:31dash spaces into just the space en-dash space.
01:35All right. So that's one of the ones that Adobe gave us. Let's look at another
01:38one then here. How about Remove Trailing Whitespace? This is a little simpler,
01:43\s means any whitespace. So that could be a space character or a tab character
01:49or a return, anything that's just whitespace and then one or more of them. That
01:53little plus there means one or more of the previous character. So one or more
01:58whitespace characters and then what's this dollar sign?
02:01Well I'm going to be talking about location codes a little bit later on in
02:04quite some depth, but I'll just tell you know, I'll give you a little hint.
02:08That means at the end of a paragraph. So this is one or more white spaces at
02:13the end of a paragraph. And because Find What is filled in and Change To is
02:17empty and the Find Format and Change Format fields are empty as well, that
02:22means it's going to search for all of these white spaces and if I hit Change
02:26All, it's going to delete them all. So it deletes all of the whitespaces at the
02:30end of a paragraph. Let's try it out.
02:32I'll click Find and it jumps right over to this one. There is a whitespace
02:36there, I better say Change/Find and Change/Find. And you could see it's just
02:40removing all of these things. I can't even see all of these. Let's zoom in here
02:44to 200% and I'll turn on Type > Show Hidden Characters, there we go. I can
02:49actually see the little dot there, the green dot means that it's a regular
02:52space there at the end of the paragraph.
02:54So I'll say Find it. Yep, there it is. Change then find, change then find. It's
03:00finding all of those whitespaces and removing them. It could be 1 or 15 or 100
03:05spaces in a row. It doesn't matter. It will find all of them.
03:07In fact this code will even find multiple returns. I just place the cursor at
03:12the end of that paragraph and hit Return or Enter a couple of times to move
03:16down. So I have these blank paragraphs down here and this code will find that
03:21as well. Let's try it out. I'll place my cursor above the text, click Find.
03:25There it goes. It found it. I can't see everything on my screen here but it did
03:29find it. It found all of those.
03:31In fact if I click Change All, it will go through my entire document and it
03:35will delete all of them including those blank lines. Well that may be what you
03:39want. Maybe that's exactly what you want and that's great or maybe it's not
03:43what you want. You wanted it remove the spaces and tabs at the end but you did
03:47not want it to remove the blank returns. If that's the case, well we better
03:52massage our code a little bit.
03:54So I'm going to undo that with a Command +Z or a Ctrl+Z on Windows and I'll come
03:58in here and change the code. I'll delete the Any Space character, this wild
04:02card, and I'm going to instead tell it exactly which kind of spaces I want it
04:06to look for. So I'm going to put it inside of a square bracket. So I have an
04:11open square bracket and I'm going to say find me any, let's say tab.
04:16How do I type the tab code? I don't know. But it's easy to pull it out of that little
04:20@ sign flyout menu here. Tab, oh, there it is. It's \t. So it typed it for me.
04:26Then maybe I want just any regular space. So I'll just type the space on the
04:30spacebar on the keyboard and that typed that kind of space and then maybe we
04:34want some other kind of spaces as well. I'll come out here to the White Space
04:38pop-up men in the @ sign flyout menu here and I'll say let's find any em-space
04:43as well. Then I'm going to close that expression with a close square bracket.
04:49So it's tab or a regular space or an em- space, and I want one or more of them,
04:54so my plus sign is there, and I only want it at the end of the paragraph and
04:58that's why that dollar sign is. Now when I say Change All, it will go to the
05:02entire document, 21 replacements made, click OK and it removed all of them but
05:08it did not find or replace my blank returns.
05:11Okay one last thing that we're going to search for here, let me pan down to
05:16this e-mail address. I want to find e- mail addresses in my document. So how am
05:21I going to do that? Well I need a new code. So I'll go ahead and delete that
05:24one and I'm going to start building my code for e-mail addresses. This is
05:29really exactly how I build these codes. I don't memorize the whole thing;
05:32I build it piece by piece.
05:34So I'm going to start with an @ sign because I know all my addresses have an @
05:37sign in them. Now on the right side of my @ sign I know that I want characters
05:43because I know it's going to be lowercase or uppercase characters. So I'll find
05:47my wild card that is Any Letter. There we go. Any lowercase or uppercase
05:52character and I know that I want one or more of them. Not just one character
05:57but I want it to repeat it one or more times.
06:00I also happen to know that there's a 5 in here. So I need a digit as well.
06:04Lowercase character, uppercase character, or I'll click just after the u there.
06:09I need a wild card for any digit. That's a \d.
06:13So now I found any lowercase uppercase or digit, one or more of them after the
06:18@ sign, and what about before the @ sign? Well that's easy. I can select all of
06:22that, copy it with Command+C or Ctrl+C on Windows, click before the @ sign and
06:28Command or Ctrl+V to paste it in here. So now I'm searching for some text, some
06:33words, @ sign and then another text or word. Let's try it out.
06:37I'll place my cursor up here, click Find. Uh-oh! It didn't get the whole e-mail
06:41address. It got the text before it and the @ sign and this but it didn't get
06:45the .com. Why? Well you see always making mistakes. You always have to look at
06:50it and troubleshoot the GREP code. I can see that - Oh! You know what? It's
06:54searching lowercase, uppercase or digits but it's not finding this little dot,
06:59the period there. So I better type the period. Because it's inside the square
07:03brackets I can just type the period on my keyboard before and after it because
07:08there might be a period before it as well.
07:10That is going to be a pretty robust GREP code for finding my e-mail addresses.
07:15Maybe there would be hyphen, I don't know, maybe there is underscores. I could
07:18add those to my expression as well. But for right now in this document
07:22I'll keep that relatively simple here and see if this works. Let's say Find it. Yep,
07:26there we go, it found the entire e-mail address.
07:28Well now once I've found it, what am I going to do with it? Well I would like
07:32to apply formatting to it. I'm not going to change the e-mail address, I'm just
07:35going to apply formatting to it. So I'm going to do that by clicking down here
07:39in the Change Format field, and when we're inside this field, we'll open the
07:43Change Format settings dialog box and I'm going to apply a character style to it.
07:48So my character style is going to be my e-mail style. I don't see one here.
07:53So I'll go ahead and make a new one.
07:55This is one of my favorite new features in InDesign CS4, the ability to create
07:58a new character style without having to close the dialog box then come back to
08:03it later. Just pull it right out of that pop-up menu and this is going to be my
08:07e-mail style and I'm going to change the font let's say I'll make it Myriad and
08:12I'll change the color so it'll be more obvious on screen here. Why don't we
08:16make it this kind of burgundy color? So it will fill with a burgundy color.
08:19Click OK, click OK.
08:22So now I can see that I have a code in the Find What field but nothing in the
08:26Change To field. Does that mean it's going to delete the e-mail address? No.
08:30Because I have chosen something in the Change Format field. So when I have
08:34something in Find What and something in Change Format, but nothing in Change
08:38To, it means don't change it, ignore it. Don't change the words at all, just
08:43apply formatting to it. Let's try it out. I'm going to click Change All and it
08:48went through my whole document, it made the re-replacements and you can see
08:51that it changed all my e-mail addresses into this character style.
08:56Okay the last thing I'm going to do here is save my Find/Change query. Because
09:00if you've spent more than 30 seconds on one of these GREP codes, you should
09:03save it. I mean you're probably going to want to use it again later.
09:05So to save this, just go ahead and click this little disc icon and it saves it to disc.
09:10I'll call this my format e-mail addresses. Click OK and now that shows up
09:18in my Query pop-up menu as well.
Collapse this transcript
3. Using GREP for styles
00:05I'm going to zoom into the lower left corner of this page and I can see that
00:08inside these paragraphs, I have numbers and I want to apply special formatting
00:12to just the numbers.
00:14Now, I know that I could use the Find/ Change dialog box to type in special GREP
00:18codes and apply formatting using those codes, but the problem is what happens
00:22if my text gets changed? If I add a number somewhere? Well, that's a big problem
00:27because I would have to run the Find/ Change query over again. Kind of annoying.
00:31So wouldn't it be cool if there were some way to apply formatting using GREP
00:35codes that would happen automatically in the background? Just add a number and
00:40boom, it would change. Well there is and it's called GREP Styles. And it's one
00:44of my favorite features in InDesign CS4. Let me show you how it works.
00:48You can apply GREP Style to a single paragraph if you want to, just by
00:51selecting that paragraph or any part of that paragraph, coming up to the
00:55control panel fly-out menu and choosing GREP Styles.
00:58The problem with doing it this way is that it affects just that one paragraph.
01:02That's kind of annoying because I wanted to change my entire document not one
01:05paragraph. So I never use this I just wanted to show you that it is possible,
01:09you can change a single paragraph. I'll cancel out of that and instead
01:13I'm going to go to the Paragraph Styles panel. This makes a lot more sense.
01:17Edit the Paragraph Style that is applied to all of these paragraphs.
01:21In this case it's Body, so I'm going to right-click on Body choose Edit and
01:25then move over here to the GREP Style pane of the Paragraph Style Options dialog box.
01:31Now this user interface is a little bit clunky, it's not very intuitive in my
01:34opinion, but once you see how to do it once it's totally obvious. You will get
01:38it right away. Let me show you. First click New GREP Style then type the GREP
01:44code that you want to search for inside that your text field. Well, this is a problem.
01:49It doesn't look like there is any kind of editable field here, right?
01:52Well, there is. How do you get it editable? You just click on it,
01:55just click once and boom.
01:56Now it's editable and we can see that this GREP code is backslash d (\d), which
02:01is the code for a digit, and then the plus symbol, which means one or more.
02:05So this is the code for one or more numbers, which is in fact exactly what I was
02:10aiming for. So I don't even need to edit this default GREP code at all.
02:13Now I need to choose a character style from the Apply Style pop-up menu here and once
02:18again it doesn't look like there is a pop-up menu, until you click on it, then
02:22it activates it. So I'll go down here and I'll see that I don't have one that
02:26I want to apply yet so I'll choose New Character Style. And I'm going to say this
02:30is my number style and why don't I go ahead and change the color to something else?
02:35Maybe magenta and maybe I'll change it somehow like make a Proportional Oldstyle.
02:41So it's going to be a different color and it's going to be Oldstyle.
02:44Because I have the Preview checkbox turned on here, I'll move the dialog box over a little bit,
02:49you can see that all the numbers in all of these paragraphs get
02:52changed to magenta and the Oldstyle numerals, pretty cool. I'm going to click
02:57OK here and I'm going to scroll over, pan over here to this paragraph up at the
03:02upper right corner and I can see that there are fractions in here. That's interesting.
03:07Fractions are going to be different. Fractions can be a real pain in
03:11InDesign, but there is the open type fraction formatting that you can apply but
03:15it's just really annoying because you can't apply the fraction formatting to
03:18the entire paragraph because all of your punctuation will go berserk. So,
03:22instead you only want to apply it to things that look like a fraction. Well
03:25I said looks like a fraction, right that sounds like I'm defining a pattern,
03:29things that look like a fraction. Let's go ahead and see how it's done.
03:33I will double-click on Body because that's actually what's still selected here
03:36and I'm going to go the GREP Style pane here and click New GREP Style and
03:40this time I'm going to apply a fraction style to anything that looks like a fraction.
03:46\d, plus because I want it to be one or more numbers, followed by a
03:50slash, just a regular slash on the keyboard followed by \d+. There we go.
03:55That's what a fraction looks like.
03:57One or more numbers followed by slash, followed by one or more numbers and
04:01I'm going to apply a special character style to it, New Character Style. I don't
04:06know why the document reflowed in the background there that's kind of weird
04:09probably a little redraw glitch there, sometimes InDesign does that. That's okay.
04:12I'm going to come to the OpenType Features and I'm going to turn on
04:15Fractions. And in fact, I'll call this my fraction style and I might as well
04:21also change the color because I wanted that magenta colored numbers I'll make
04:25this magenta as well. Click OK, click OK and then zoom back up here and we can see,
04:32there we go.
04:33Now I automatically get true fractions because fractions are inside this font.
04:38But remember it's not just the text that's already there. If I later go in here
04:42and edit the text perhaps add a new fraction, then it will update
04:46automatically. For example, I'll delete that 1 and you can see that now it's
04:50not a true fraction anymore, but if I change it to a 7 it becomes a true
04:54fraction. If I come over here and say 22, I get the regular numeral character
04:58formatting. slash and then 7. As soon as I type that 7, InDesign says oh,
05:04well that matches my pattern, one or more digits followed by slash followed by
05:08another one or more digits. Looks like a fraction; let's apply the fraction style to it.
05:13So GREP Styles are very, very powerful. Let me show you one more example of how
05:17I use GREP Styles, I use this all the time. Let's jump over here to page 6 and
05:23I'm going to zoom in here to this text. Bliss No. 5, my company name.
05:29So I select it and press Command+4 or Ctrl+4 on Windows. You can see that even here
05:33because we assigned numbers in this Paragraph Style, it's showing up here as well.
05:38But I want to apply special formatting to this whole company name, Bliss No. 5.
05:44How do I do it? I'll go back to my Body text, double-click on it to edit it,
05:47hit GREP Style, make a New GREP Style, and this time I want a special GREP Style
05:53that targets just my company name and it's going to be Bliss No. 5.
06:00there is nothing special about this. It's literally just that text.
06:04Anytime that it finds Bliss No. 5, there is no special codes. Whenever it finds this text,
06:09it should apply my special New Character Style called my company style
06:15and once again we'll go and change this to -- how about something, how about
06:18Myriad Pro Semibold? Let's do a different color now, how about blue?
06:23And that looks pretty good.
06:24Well, one more thing that I often do here is in Basic Character Formats,
06:28I'll turn on No Break. So my company name will never break across two lines.
06:33It won't hyphenate and it won't break across lines. It will always stay together.
06:37I like that. Click OK, click OK and we can see that it changed the formatting
06:42and No Break was automatically applied to it. So it will never break across
06:46multiple lines.
06:47I love GREP Styles. It's an incredibly efficient way to apply formatting to any
06:51pattern of text inside of a paragraph.
Collapse this transcript
4. Escape characters
00:05I would like to apply a special GREP Style to all the dollar amounts in my
00:08document. For example, down here in the lower left corner of this page I have
00:11got some dollars here and dollars here. I would like to apply different kind of
00:15formatting to that. So I'm going to go to the Paragraph Styles panel and
00:19I'm going to double-click on this. Just so it selects it, I see this is Body text,
00:23so I'll right-click on it or Ctrl+Click with one button mouse and say I want a
00:27New GREP Style here.
00:29The new GREP Style is going to apply a character style called dollar amounts and
00:34we'll change the color just so that's a easy way to really stand out,
00:37you can see that it is different and it's going to apply it not just to the numbers.
00:42Right now it's just the numbers, but I want to apply it to the entire dollar amount.
00:45So how would I do that?
00:48Well, you might think that you could do something like dollar sign, let's say
00:52one or more digits and then period and then remember that if you can't recall
00:57the codes for things like digits, you can always pull them out of these fly-out menus
01:01and then pull things out of like Wildcard > Any Digit. So, easy to do it there as well.
01:06So one or more digits here, in fact this case is just two digits. So one or
01:09more digits, followed by a period, followed by two digits. And you think that
01:13would work, but it doesn't. In fact, if I click off here in the blank area,
01:17you can see that it completely fails.
01:18Now, none of the digits are being found at all. Why? Well, the problem is GREP
01:24reserves certain characters for its special codes. For example the dollar sign.
01:29The dollar sign means something to GREP. So GREP looks that and says, well,
01:34the dollar sign means end of a paragraph. Well, we don't want it to mean end of the
01:38paragraph. Well, we need to do what's called escaping it out. We need to tell GREP
01:43to stop thinking of this as a code and start thinking of it as a dollar sign
01:47character itself. And the way you do that is simply by placing a backslash in
01:52front of it. So we can do \$ and GREP says, oh you mean the real dollar sign.
01:57Okay, I got it.
01:58So \$, \d, which is the code for digit and then that dot here, the period, also
02:05means something. We wanted to mean the actual period symbol. But GREP says
02:10the dot means any character. Any character, it doesn't matter what it is.
02:15It's looking for any character and that's a problem. So we need to escape it out.
02:18Once again, just put a backslash in front it.
02:21So it makes it a little bit ugly, \$, \d and so on. But that is the code for
02:27the dollar value itself. I'll deselect here, and we can see that the code worked.
02:32Because the Preview checkbox is on, we can immediately see that that character
02:36style was applied to the full dollar amount.
02:39Let's try another one. I'm going to create a New GREP Style and this case
02:43I'm going to create a New GREP Style for anything inside of parenthesis.
02:47So I'll type open parenthesis and then dot which means any character, right. That's a
02:52special code for any character and then I'll place a plus sign, which means one
02:56or more of any characters, and then closed parenthesis. And the character style
03:01I'm going to apply it to is, let's make a new one for stuff in parens and this
03:07is going to be in different colors. Let's make it Beige and let's make it
03:10Myriad something like that, click OK and we can see that, oh my goodness,
03:15what happened? All the text got changed.
03:17Well once again, we have a problem because of special reserved characters.
03:22The parenthesis is a reserved character. So we need to escape it out. How do we do it?
03:27Well, we could just put a backslash in front of it or if we don't remember
03:31that backslash trick, we can always just delete it and come out to the fly-out
03:35menu and look for the symbol here and right inside the Symbols fly-out menu,
03:40we can see closed parenthesis character. There we go. And all it is, is backslash
03:43parenthesis. There you go. Now that should work. Click off of it and we can see
03:47that all the stuff in parens including the parens gets that applied to it.
03:52Because this GREP Style comes after this GREP Style, it overrides it.
03:56So it goes down the list in order. If we want the dollar amounts to be
04:00formatted differently then the rest of it. We can move it down by selecting it
04:04and clicking the down button. And now this comes second, so it overrides the
04:09stuff in paren style. I'll show you one other example of the Escape feature.
04:13Let's zoom out here and I'm going to use Shift+Page Up to come back to page 5 here.
04:18And then why don't I zoom in on just this text so we can see that?
04:22I'll just select it and then Command+4 or Ctrl+4 on Windows, just to zoom into 400%
04:26and I can see that I have got a really wacky bit of text there and I want to
04:30find that kind of text using GREP for some reason.
04:33So I could open the Find/Change dialog box, Command+F or Ctrl+F on Windows and
04:39why don't I move this over so I can see both at the same time and I want to
04:42type that into this Find What: field, of the GREP tab of the Find/Change dialog
04:46box. That's (a+b*c?). Well the problem here is these are all reserved
04:54characters, well not a, b and c but the rest of it is reserved characters. So
04:58that's is going to cause me all kinds of grief.
05:00Fortunately, GREP has a way to escape out a whole clause, a whole phrase as it
05:06were and the way you do that is before the phrase, I'm going to place the
05:10cursor just to the left of the parenthesis here and I'm going to do a \Q and
05:15then at the end I do a \E and this is kind of undocumented. You are not going
05:21to find this one in this fly-out as far as I know. I don't think it's hiding in there,
05:24but that means escape out all of this phrase and find exactly that.
05:30Let's try it out. I'll make sure my cursor is up here and then I say Find and
05:34boom! it worked. Perfect! Great! It looked for that and ignored the reserved
05:39GREP Codes in there because I escaped those characters with the Q and the E.
05:43Forgetting to escape characters is one of the common mistakes that you can
05:47make when you are creating your GREP expressions. So whenever something fails
05:50and you are troubleshooting it and you are trying to figure it out, make sure
05:53you look at each one of those characters and ask yourself, do I need to escape
05:57that character or is it actually supposed to be a code?
Collapse this transcript
5. Finding how many and how long
00:05I want to find the word chocolate or chocolates. Either chocolate singular or
00:10chocolates plural. So I'll open up the Find/Change dialog box with a
00:13Command+F or Ctrl+F on Windows, and if I would just search in for chocolate by
00:17itself I could do that in the Text tab of the Find/Change dialog box.
00:21But in this case I'm going to be typing a pattern in. So I'm going to use the GREP tab instead.
00:27So I'll type Chocolate and then I want to say sometimes it has an S on the end,
00:32and I don't know which one it's going to be. So I need to tell InDesign with
00:36some kind of special code that the S may or may not be there.
00:40Now the code I'm going to find inside the @ sign fly-out menu. I'll come down
00:45here to Repeat and I'm going to say this is going to Repeat Zero or One Time.
00:51This Zero or One Time code, which if I selected you can see is a question mark,
00:55is a great way to find words or phrases when a single letter may or
01:00may not be there.
01:01In this case it will find Chocolate and then the S could be there or could not
01:06be there. Now let's go ahead and come out here, I'm just going to click out
01:10here and zoom into 200% view so we can see whatever the results are, little bit
01:14better, click Find, and there we go. Chocolate it founded, click again
01:18chocolate, chocolate, this is pretty good, oh, it's finding lots of chocolate,
01:22I like chocolate. I'm just going to keep clicking on here until it proves the
01:26point that indeed it will find chocolates as well. There we go, chocolates,
01:30Bliss no.5 Chocolates. So it found one or the other.
01:34Now remember that it's only finding because it's case-sensitive. So only
01:38uppercase C and then Chocolates. If I wanted to find both uppercase or
01:42lowercase I would have to type-in a different code. Lowercase or uppercase
01:47inside square brackets, let's go ahead and try that. And I'm just going to keep
01:51clicking Find, oops, there we go. There is a CHOCOLATE.
01:53Now it looks like it's all uppercase when here it's lowercase. What's going on
01:58there? Well, I can see if I look up in the control panel here that the All Caps
02:03formatting is applied to this. So this text must actually be or behind the
02:08scenes lowercase, but the all caps is making it look like it's uppercase.
02:13Here is another example of when that question mark code might be useful. Maybe
02:17I have the word color in my document, but sometimes it's the Brit spelling with a U.
02:22I put a question mark after it and now it will find both color with a U or
02:27without a U. It could go either way very, very useful to sort of expand the
02:32options of what this will find. I don't actually have the word color in here so
02:36I'm not going to search for that, instead I'm going to search for a different
02:39code, I'm going to search for everything in parenthesis. But in this case
02:44I'm going to zoom back here and go to a particular page where I know there is going
02:49to be a problem. There is always a problem in here.
02:51I am going to go to page 8 here and zoom into 200%, and I can see that this
02:56paragraph has two different sets of parenthesis. So why is that important?
03:00Well, I'll move that out of the way a little bit. I'll open my Paragraph Styles
03:04and I'm going to Edit my Body text style here, and I'm going to edit it with a GREP Style.
03:09I am going to add a GREP Style here, how about we set this for -- just make a
03:14new one, it will be easier, and I'll say this is going to be Myriad Pro,
03:18Regular, let's change its color so it really stands out here, Beige color,
03:22click OK, and it's going to be everything that is within a parenthesis.
03:27So I'll say open parenthesis, and then pretty much everything that shows up between that
03:33and the closed parenthesis. I'll just type that backslash parenthesis, /),
03:37click off here we can see that it kind of worked and kind of didn't.
03:41It applied it to this phrase in here inside these parenthesis but then it just
03:45kept on going, kept on going, kept on going until this one. Well, this is an
03:49issue with GREP. GREP is what's called greedy. It will always grab as much as
03:54it can within a paragraph.
03:56Now if you wanted to be less greedy, if you wanted to just choose the shortest
04:01match that it can get in here you need to choose a different code, and it shows
04:06up there in the Repeat fly-out menu, let's go and take a look, it's good thing
04:10that the Paragraph Styles Options dialog box is still open, I had the Preview on.
04:15So I don't even have to go back to edit it, I simply click on here again. So
04:19I'm going edit this code so that it is less greedy, and the key here is instead
04:24of that little plus sign there I'll delete that, I'm going to say find me
04:28everything, the dot means find everything, any kind of character, but not
04:33Repeat One of More Times like I was using instead I'm going to use it One or
04:37More Times (Shortest Match). That Shortest Match is very, very important in
04:42this kind of circumstance, and the code is +?. So that means grab any
04:48characters, the string of characters, but keep it the shortest match possible
04:52before the final parenthesis. I'll click off here and you can see that now it's
04:56working perfectly. It's applying it to this phrase inside the parenthesis, and
05:00this one, but not the text in between.
05:03Okay, one more quick repeat trick that you might want to use. I'll choose a New
05:07GREP Style here, and I'm going to make a new style which is going to be just
05:11for my years, anything that looks like a year, four digits in my document. Why
05:15don't I just go ahead and change this. I'll just change the color to something
05:18bright, so we can really see it like Magenta, click OK, and it's going to be
05:22not a string of digits of any length instead it's going to be only four digits
05:27long. Only find me four digit long characters with no other characters in
05:31between like no commas or anything. The way you do that is you do it {4}, and
05:38that means find a string of four any digits. Any digits, but only four of them
05:44in a row. And that's a little undocumented trick. It's certainly documented in
05:47GREP documentation but not in InDesign. I mean there is nothing inside this
05:52fly-out menu that would indicate that you can do this kind of code. That's one
05:56of those things that you just have to know how it works.
05:58I will click OK. I'm just going to go find that in the text itself, and
06:03if I don't find one I better just go ahead and type one. So I'll just come in here
06:06and say 2009 and as soon as I finish four digits in a row it applies the GREP style to it.
06:13When you are typing out a GREP code it's imperative that you have absolute
06:17precision when you are defining the pattern you are looking for. These Repeat
06:20codes like the Zero or One Time or the One or More Times really help you to
06:25find that pattern so you find exactly what you are looking for.
Collapse this transcript
6. Specifying text location in a paragraph
00:05One of my favorite usages for GREP is to apply Paragraph Styles and Character
00:09Styles to text in a long document. For example in this file I have some lists,
00:14and this list is just not consistent. I guess somebody actually typed 2 and
00:19then there is a period, and then a space, but up here there is a bunch of
00:21spaces and down here there is a number, a period and a tab.
00:25So in some cases there are tabs, in some cases there are spaces. I really wish
00:29I could get rid of all of that and just apply InDesign's automatic numbering.
00:33That way I know it will be consistent and look just right throughout the document.
00:38So how can I do that? Well, I'll open up the Find/Change dialog box with the
00:42Command+F or Ctrl+F on Windows and I'm going to type in a GREP code that
00:47defines this pattern. This pattern is going to be a digit. So I know that's /d
00:52and I'm going to say -- actually there might be more than one digit because
00:56maybe it's one digit or maybe it's ten or eleven, maybe it's more than one digit,
00:59and I think that it has a little dot after it. Most of these seem to
01:02have a period, but I know that the period code means any character.
01:07So I need to escape it out.
01:09I will press the left arrow key on my keyboard and put a \ before it. So this
01:14means a period itself, look for that actual character. Now it might be there or
01:18in some cases it might not be there. Maybe they forget to put in. So I'll put a
01:22question mark. So that says this period may or may not be there.
01:25Now their may or may not be a space there. So I'll do a \s, and there is
01:30probably one space or two spaces, or I don't know how many, let's go to the
01:34fly-out menu and choose Repeat Zero or More Times. So it might be there or it
01:40might be one, two, three... we don't know, and that's the asterisk code.
01:44So that's looking pretty good. That seems to define the code we are looking for.
01:48Let's try it. I'll click Find and we can see it found that 5. That's good.
01:52Find Next and that seems to work there. Uh-oh! That's not working at all.
01:57What happened? It found a number right in the middle of a paragraph. Well, it was a
02:02number and it was followed by a space, but that's not something we want to find.
02:06We need to define the GREP code even further and specify exactly what we are looking for.
02:12In this case we need to tell the GREP code to only consider numbers at the
02:16beginning of a paragraph.
02:18So I'll place the cursor before that initial backslash. I'm going to go out to
02:22this little @ sign fly-out menu and I'm going to give it a Location. The
02:26Location pop-out menu offers me five choices, Beginning of Word, or End of
02:31Word, or right out of Word Boundary. In this case we want to use Beginning of
02:35Paragraph and only Beginning of Paragraph, which is the caret symbol.
02:39So this pattern has to be at the beginning of a paragraph. Let's try it out.
02:44Click Find Next, and it finds it, click Find Next, and it finds it. So this
02:48seems to be working just right. Now what do we want to do to this GREP pattern.
02:52Well, we want to apply a paragraph style to it. So I'm going to do click down
02:56here in the Change Format field, brings up the Change Format Settings dialog
02:59box and I'm going to say I want to apply my numbering list Paragraph Style to
03:05anything that matches this style.
03:07Let's go ahead and click Change All and see what happens. It went through my
03:10whole document and it seemed to work but I didn't quite work the way I wanted it to.
03:15It applied the style, that's great, but it did not get rid of the text that
03:20it found. I still have this 8 period space, space and so on.
03:24So I wanted to get rid of it, and I left to Change To field blank so you would
03:28think that it would delete it, right? Well, true except that there is this
03:33little i here. That i means that this formatting applied to it and when you
03:37have Find What filled, Change To blank but the i here, some format applied to
03:43it, that means go ahead and leave the text there. So in order to make this work
03:47I need to do one more little thing. I need to search for one additional
03:52character. I'm getting ahead of myself here a little bit but I'm going to let
03:55you in on a secret and that is, I can take text from here and put it down here
04:01if you put it in parenthesis. And the text that I'm going to take is any single
04:05character. That period means any single character that it finds.
04:10And because it's in parenthesis I can put that character down here with a
04:14special code and that code is $1. Now dollar sign up in the Find What field
04:21means it's a Location tag, it means only find it at the end of a paragraph.
04:25That's what dollar sign means. But dollar sign down here in the Change To
04:28field means something very different. It means take whatever was up here inside
04:33this parenthesis and put it down here in the Change To field automatically.
04:37All right, so I'm going to Undo this, Command+Z or Ctrl+Z to go back to where I was,
04:42and now we'll try it one more with this extra code. One more time it's
04:46going to search for at the beginning of a paragraph, look for one or more
04:49digits followed by maybe a period, maybe not, followed by maybe some space,
04:54maybe not, followed by anything. And then take that anything and put it down
04:58here and while you are at it format the whole paragraph. Will it work? With one
05:03click we can see that it formats the entire document quickly. We have deleted
05:08the text that we didn't want there and applied the paragraph formatting.
05:11Now let's take our new found knowledge of setting location to do one more
05:16search here. I'm going to delete these and start from the beginning. I want to
05:20find only whole words that begin with c and end with e. So I'm going to say c
05:25and e, I know that's there. I know that there is any lower case character in
05:30the middle so that's going to be \l with a plus. So one or more other
05:34characters between the c and the e, but not just any c followed by some letters
05:39followed by e. Only ones where the c is at the beginning of the word and e is at the end.
05:44So to do that I place my cursor before the c, I can say at the beginning.
05:49At the beginning is going to live in the Locations pop-up menu and we could use
05:53either Beginning of Word or Word Boundary, either one works. I'll choose Word
05:57Boundary here, and then I'll put another Word Boundary over here. So it says at
06:01the Word Boundary start with the c. At the other end of the Word Boundary end
06:05with an E. Let's try it. Click Find and it finds Chocolate, Find again,
06:10chocolate. Find again, and it keeps, oops. There is another one, starts with a
06:14c and ends with an e, but it's not chocolate. So I know that my pattern worked.
06:18If you don't specify a Location code for your GREP code it will find it
06:21anywhere, in the middle, beginning, end of a paragraph, you don't know where.
06:25But when you put those codes in that's you specify exactly what you want to
06:29find and where you want to find it.
Collapse this transcript
7. Reusing, recycling, and reordering
00:05I was once working on a book project that had a lot of historical dates in it
00:09like 1492. So I send the manuscript in and when it comes back from the editor
00:14all of those dates had commas in them. Like suddenly it became 1,492.
00:20I was flabbergasted. What I'm supposed to do with that? I actually had to go through
00:24and fix every single one of those dates removing just the comma, and that would
00:28have been a nightmare without GREP.
00:30Now this is not the document I was working on. But it has the same problem.
00:35All of the years have commas in them, and I'm going to show you how I can use GREP
00:39to remove just those commas.
00:41To do this I'm going to open the Find/ Change dialog box with a Command+F or
00:45Ctrl+F on Windows, and I'm going to type in the GREP tab. The code I'm looking
00:50for is a year and years are going to be based on numbers. So I need an any digit.
00:55That's \d, any digit code.
00:58In this case I know the first digit is followed by a comma, so I'll type a comma,
01:02and then I could just do three more of these digits. There is the number
01:06digit followed by a comma and three more digits. There is one problem here and
01:11that is that this will find any four- digit number that has a comma, and the
01:14ones I want only come after dates. And I happen to know that in this document
01:19all the dates are something like March 4th and then the year.
01:23So I'm going to go to the beginning of this GREP code and I'm going to put in
01:27another digit followed by another comma and then a space, because I know that
01:31this will find all the instances where its a date and then the date of the month
01:36followed by a comma and then the year. Let's try it out. I'll click Find and it
01:41jumps right to the first instance. Find Next and it goes to the next. Pretty good.
01:45But now here is the problem. I need to take all of these except the comma and
01:50put them into the Change To field. Whenever you want to take text that's set up
01:53as a wild card in the Find What field and put it in the Change To field, you
01:57have to put it in parenthesis.
02:00So for example, I'll put a parenthesis before this first digit and the first
02:04comma and that space, because I want to save all of that, and I'm going to put
02:09it down here with $1. Whatever is the first instance of the parenthesis gets
02:14put into what's called $1 GREP code.
02:18Now I'm going to grab the second digit that I want which is the first digit of
02:23the year and I'll put that down here as well, with a $2. The second parenthesis
02:29is a $2. Now I don't want that comma there but I'm going to grab it anyway, and
02:34then I'll grab that final chunk, the last three numbers in here and I'm going
02:40to put that down here with $4.
02:43So I want 1, 2 and 4, but I'm leaving out 3, which is the comma. I notice that
02:48in the Change To field the little eye icon is here which draws my eye down to
02:52the bottom and I can see it has some formatting applying to it. Always be
02:56careful of that little eye when you do not want to apply formatting, in this
03:00case I certainly do not.
03:01So I'm going to click on the Trash Can icon to make that go away. Now let's go
03:05ahead and try it. I click Change All. It went to the whole document and in one
03:10click it changed all the years throughout the entire document, 55 of them much
03:15faster than it would have been by hand.
03:17Okay this is great. Now let's go ahead and do something a little bit more
03:20tricky. Let's reverse the order of these names. I want the last name first.
03:24I want this to be Monroe, James. Adams, John Quincy. Can we do that with GREP?
03:30Sure no, problem.
03:31Let's start over. I'm just going to delete these, and I'm going to type in some
03:35codes that will find those names. The first thing I know about these names is
03:40that they are at the beginning of the paragraph. So I'll go to the flyout menu
03:43here, go to Location pop-up menu and say this is going to be starting at the
03:47beginning of the paragraph. Then I need to define what it is that I'm looking for.
03:51I'm looking for something that looks like a name, and I'm going to put it
03:54in parenthesis because I know that I'm going to be wanting to use later.
03:57So I'll open the parenthesis and then I'm going to find something that's a wild
04:01card called the Any Word character. Any Word is like an uppercase or a
04:05lowercase character or a number, lot characters fall into the category of
04:09letter that might be in a word. That's \w, and I'm going say there is going to
04:13be one more of those.
04:15I know that this word is always going to be one or more characters. The Space
04:19character however never fits into the word. So this will not match that first
04:23space character. It will go up to the end of the first word.
04:25Now I have got a problem because in some of these cases I have got James
04:29Monroe, which is two words, and in some I have got three words, John Quincy
04:33Adams, and in some I have like Ulysses S. Grant. So there is an initial in the
04:38middle. I need to be able to search for all of those and handle them properly.
04:41I know that I'm going to be needing whatever it is that I'm capturing later, so
04:45I'm going to just start with a new open parenthesis here and I'm going to type
04:48in a code for any of those things that might appear and it's going to be an
04:52either or situation, so I'm going to use a square bracket. It's going to be
04:56something inside the square brackets, which means this or that.
04:59I know it might be a space there or maybe there is a individual word character
05:04like \w or maybe there is period, and because its inside one of these square
05:09brackets I don't have to escape it with a backslash. I'll just leave that as a
05:13period. So it could be any of those things coming next. And I know that there
05:17may be more than one of them, so I'll put the plus sign there. So this is going
05:21to be one or more of either a space or a word or period.
05:25Now I'll close that parenthesis because that's going to close the next little
05:29chunk that I'm going to using later. But is that chunk always going to be
05:32there? Well in the case of a two-word name it's not going to be. All I want is
05:38the first and the second piece, there is nothing in between.
05:41So in this case I'm going to put a question mark after that little chunk of
05:45code there. So this whole parenthesis might be there or it might not be.
05:50What I do know is always there is a space. There is always going to be a space between
05:54these two characters. So I just type a space here in the Find What field.
05:58And now for the last name. The last name is going to be pretty much the same as
06:02the first. Any word space more than one but it always is going to be followed
06:08by a comma. So I'll just type a comma in there, and then close my parenthesis.
06:12It looks complex but let me just go over it one more time. Beginning of the
06:16paragraph any word with one or more characters followed by a word that may or
06:21may not be there which is going to be either a space or a word character or a
06:27period character. All of those things are going to be the second name and then
06:31when, again, it may or may not be there and then finally a space and another
06:34word followed by a comma.
06:36And that matches this pattern perfectly. That was the hard part. Once I have
06:40got the GREP code, now I just have to put it back in the right order. So,
06:44I'm going to say Change this to 3 because that's the third thing in the parenthesis
06:49as the last name and I want to start with my last name. So I'm going to say
06:53start with $3 then put a space in there between the names and then say do the
06:58first one first name and the second name.
07:01No space between 1 and 2 because if there was one it would have been captured
07:06by this second element here. But at the end after 2 I do need a comma, because
07:10I want to make sure that this is followed by a comma before it goes into
07:13the rest of the line.
07:15Okay let's try it out. I'm going to search the entire document and with one
07:18click I say Change All, it goes through and the all the names are reversed.
07:23So sure, using GREP codes to find text and maybe applying formatting to it is pretty cool.
07:28But being able to actually move the text around? That is awesome!
Collapse this transcript
8. Finding between
00:05I want to find all the ordinal numbers in my document like 3rd or 4th and apply
00:09superscript formatting to that rd or the th after the number. Of course,
00:14I don't want to apply superscript to all the rd's and th's throughout my
00:17document. That would be crazy. Just the ones that follow the numbers.
00:21Well, can we do that? Sure, not a problem at all if we are using GREP styles.
00:25So I'll open my Paragraph Styles panel and I'm going to right-click or
00:29Ctrl-click with a one-button mouse on Body and then Edit "Body". I'll jump over
00:33to GREP Style, add a new GREP style and I'm going to apply a new style and
00:38I'm going to call this my ordinal superscript style and I'll come over and
00:43say this is going to be a Superscript Style, OpenType superscript.
00:48I'll click OK and now I need to define what's going to get that superscript
00:52applied to it. Right now it's every digit in the document. Of course that's not
00:56what I want. What I want is th's or rd's and I put that vertical bar between
01:03the two and I'm going to put those in parenthesis just to kind of hold those
01:06together as a unit.
01:08Now again I don't want any rd or any th. I only want ones that are after a
01:13number and I don't want it to apply to the number as well. For example if I put
01:18a digit here, any digit then ordinal superscript would also apply to the digit.
01:22Well that doesn't work. So when I delete that and instead I need to say to
01:27InDesign, "look behind these letters" and in fact that's the name of the GREP code.
01:32It's called a Positive Lookbehind and I could find that in the Add pop-up
01:37menu here. Down in the Match sub-menu there is this thing called a Positive Lookbehind.
01:43That means if there is something behind this text then go ahead and apply the
01:47style and if it's not there, then don't apply the style. You'll notice that
01:51there is also a Negative Lookbehind and a Positive Lookahead and I'll be
01:54looking at this one in just a minute. But in this case I'm going to use a
01:58Positive Lookbehind.
01:59Now it's a little frustrating because the code is entered but the cursor does
02:03not end up where it needs to be for me to type what I'm looking for. Instead
02:07I need the cursor just one character to the left, in between the equal and the
02:12parenthesis, and here is where I need to tell InDesign what I'm looking for,
02:16what's behind the th or rd. And that's going to be a digit just in number.
02:21I am looking for any digit followed by a th or rd and when it finds this, apply
02:27the superscript to it. Let's click off here and I'll move this out of the way
02:32and we'll be able to see a in little tiny letters here. There is a th after 18.
02:37I'll click OK, zoom in here so we can see it a little bit better, here we go, 18th.
02:42Now I can find more of them by pressing Command+F or Ctrl+F and open the
02:46Find/Change dialog box and I'll just look for any digit followed by a th, say.
02:50Click Find, it finds that one, find it again. There we go June 5th.
02:55So it automatically is applying the correct style to the th or rd but only
03:00after a number. Here we go, there is an rd 23rd, so it applied it correctly.
03:04Now what if I wanted to apply formatting to anything inside parenthesis, not
03:09the parenthesis themselves but only stuff inside parenthesis. Well again we can
03:13do that with GREP styles.
03:15I'll edit my Body style and I'm going to go to the GREP style and I'll create
03:18another GREP style in this case I'm going to apply a new style. I'll just leave
03:22it Character Style 1, it doesn't matter but this one's going to be Myriad
03:25Regular and let's go ahead and apply a color to it so we can see it a little
03:29better, maybe this burgundy color. Click OK and we don't want it applied to
03:34digits. I'm going to apply this to anything in between parenthesis.
03:36So I'm going to start with my open parenthesis character and I know I'm going
03:41to ending with a closed parenthesis character and in between those I'm going to
03:46be finding pretty much anything. Let's say a wildcard, let's say Any Character,
03:50and I don't know what's going to be in there and I'm going to Repeat it let's
03:54say One or More Time(Shortest Match ). So just the stuff that's in between
03:59parenthesis, but the problem here is it this code finds the text inside the
04:03parenthesis and includes the parenthesis.
04:06That's not what I wanted, what I wanted was only the stuff in between the
04:10parenthesis. I can do that with a Positive Lookbehind and a Positive Lookahead.
04:15So instead I'm going to delete this parenthesis and I'm going to use my flyout
04:20menu here. Let me go grab my flyout menu. That will place my cursor just the
04:24right place, just before all of that and say Match Positive Lookbehind and
04:29between equal and the parenthesis I'm going to put a backslash parenthesis.
04:32Remember that escapes the parenthesis character.
04:35So it's going to be the opening parenthesis is behind the text I'm looking for
04:40and now I need one more of these Match Positive Lookahead and in between the
04:45equal and the parenthesis I need to have a escaped closed parenthesis
04:50character. So one more time this means any character.+?, it's going to be any
04:56character with a shortest match in which behind it is a open parenthesis and
05:02after it is a closed parenthesis. Click off of it, Preview is on, so we can see
05:07that it worked.
05:08It only found the stuff that was inside parenthesis. Of course, this doesn't
05:13have to be parenthesis, we could remove this and put let's say quote marks in
05:17instead. I'll put a double quote there and I come over here and put a double
05:20quote here and now it's just going to find stuff that's inside quotes. I don't
05:24see anything right now but no problem. I'll just come up here, let's say quote
05:29here and quote here and suddenly anything that's in between those quotes gets
05:34that Character Style applied to it, and it's totally on the fly,
05:38totally automatic and totally great.
05:40So as soon as I close that quote mark, it applies the character formatting
05:43automatically for me and that is great. It is so much more efficient than
05:47having to find these things manually.
Collapse this transcript
9. Using GREP with fonts
00:05In this document, I can see that the logo for the store Bliss No. 5 has a
00:10circle around the 5. When I zoom in on the text up here, I see that there is no
00:14such circle on these 5s. But wouldn't that be kind of cool to have a little
00:19text treatment here where the 5 has a circle around it? I'm going to show you
00:22how I can use GREP Styles to put that circle there.
00:25The first thing I'm going to do is replace that 5 with an n. Why an n? Well,
00:31I just happen to know that in the Wingdings 2 font the n looks like a 5 with a
00:37circle around. I just happen to know that. So I'm going to replace the 5 with
00:42an n here. So I'll open my Paragraphs Styles panel and I'll double-click on the
00:46Body style to create a new GREP Style. Select the GREP Style tab,
00:51now I'll click New GREP Style.
00:53You can see I already have a couple of GREP Styles in this Paragraph Style, but
00:57I'm going to create a new GREP Style, which will apply a new Character Style
01:01called let's say wingdings, might as well, and this is going to apply the
01:06Wingdings font. Actually Wingdings 2 to be precise. Maybe make it a little bit
01:11bigger than the text around it, something like that and click OK.
01:15Now, I don't want this to apply to that numbers in here. I want it to apply to
01:19the letter n but not just any n. Only n's that comes after an o. right?
01:25So I'm going to use a Positive Lookbehind and it's going to look for the text no.
01:33and of course I need to escape that period out with a backslash and then it's
01:36going to search for the character n. We can test this out by turning on the
01:41Preview checkbox and immediately you see that what was an n is now a 5 with a
01:47circle around it. So this is pretty cool. Because now any time I want to use
01:50that logo, that little type treatment, I can simply replace the 5 with an n.
01:55Let's see another example of this.
01:56I will zoom back out to this spread in window and I'm going to jump to the next
02:00spread in this document and zoom in to 400% on this text in the lower left
02:05corner. Now, this is an interesting problem because in this particular font,
02:09the l, it's a lowercase l and the number 1, the digit 1, look very, very similar.
02:15I can't even tell the difference between these. So is this 1lb or llb,
02:20or I don't know what.
02:22So I'm going to actually use GREP Styles to change the number 1 into a
02:27different font that looks similar, but is different from the lowercase l.
02:31Let's go ahead and do that. I'll double-click on this Paragraph Style now, go to GREP
02:34Style and create a new GREP Style, which is going to be a style which applies
02:40let's say Myriad for 1, for the digit 1.
02:43All I'm going to do here is apply Myriad Pro to this particular character and
02:49the character that I want is not all digits, just the digit 1. It's easy.
02:53I just have to type 1 in here and it will just look for the number 1 to apply
02:57Myriad to. Let's go ahead and click OK and we can immediately see that that's a
03:011 and that's an lb, this is a 1. I also see that there is an error in here
03:06because this was supposed to be all digits, 5 digits, and someone snuck in a
03:11lowercase l instead. So I'll hit 1 and that cleans it up.
03:15So you can see that using GREP Styles to apply a different font to one or more
03:19characters can really save you a lot of time.
Collapse this transcript
10. Making text disappear
00:05What if you want some of your text to be visible, some of the time and then
00:08sometimes you want it hidden? Well, InDesign CS4 has a cool feature called
00:12Conditional Text. And you can find that in the Conditional Text panel by going
00:16to the Window menu choose Type & Tables and then choose Conditional Text.
00:20I am going to create a new condition in here by clicking on a New Condition button.
00:25 And then I'll just name this condition which speech. How about that?
00:29Click OK and it shows up here. And I could apply that condition to each one of these
00:33pieces of text, by selecting it and then clicking on it and then going to the
00:36next line and next line but that would be really, really, really tiresome.
00:40Instead, I want to apply it quickly and the best way to do this is with a
00:44Find/Change. But because some of these are First Inaugural and some are Second
00:48Inaugural and some have no First or Second before them. The only good way for
00:51me to do that is with a GREP expression.
00:54So what I'll do is I'll open the Find /Change dialog box with Command+F or
00:57Ctrl+F on Windows. Let's bring this up a little bit. And I'm going to make sure
01:01I'm in the GREP tab and I'm going to look for one or the other thing. Let's say
01:04it might start with First, it might start with Second, I don't really know.
01:09It might just start with Inau. So I'll just start with any of those. It's going to
01:13start with one of those and then it's going to be one or more characters.
01:17Let's say the period and then plus. One or more characters and it's going to always
01:21end with the word Address. So why don't I just say ress in here?
01:25That will probably grab it.
01:26In fact, I'm also going to grab the comma afterward. And all of those things
01:31First, Second, or Inaugural Address followed by a comma I want to have a
01:35condition applied to it. So I can do that down here in the Change Format field.
01:39I'll just click anywhere down in that field. Switch over to the Conditions pane
01:43and then turn on which speech. So which speech condition will be applied to
01:49anything that matches that. Let's try it out. Click Change All. Went to the
01:54document almost instantaneously. Click Done and we can see that all of these
01:58now have little blue underlines. It's blue because that's the color of this
02:03particular condition. All right. So now it's visible, but to make it invisible
02:07all we have to do is Turn Off the Condition and they all disappear. All right.
02:11Let's try another cool trick for how to make text disappear that doesn't
02:15involve Conditional text. In this case, I'm going to go through and look for
02:19all the words that say Saturday and I'm going to abbreviate them Sat. I don't
02:22know if I would really want to do this particular thing to this document. But
02:26let's say that's what my art director told me to do, so I'm just following
02:29directions. Saturday should be Sat. I'm not going to truly get rid of the
02:34urday, but I want to hide it. I could do it with Conditions, but I'm going to
02:39show a different kind of fun little trick that you might be able to use for
02:42this sort of thing or any other time that you want text to disappear.
02:46I am going to do this with GREP Styles. So in the future, if I ever type
02:49Saturday it will automatically update and abbreviate. And I'll do that by
02:53double-clicking on List of dates. All of these have the List of dates,
02:56Paragraph Style applied to it. And I'm going to add a GREP Style to it. And the
03:00GREP Style is going to simply look for that text, the urday. So I'll type that
03:06in urday. But it's only going to find it if it's after the Sat. So I better put
03:12a Match, Positively Lookbehind Sat, something like that.
03:15Okay, Saturday but it's going to find the urday. So what do I want to do with
03:20that. I want to make it disappear. So I better make a Character Style that
03:24makes text disappear. I'm going to call this the disappear Character Style and
03:29here is how I make text disappear in InDesign. I'm going to set the Size of
03:33this text to 1. Really tiny. All right. I'm going to go to the Advanced
03:38Character Format and I'm going set the Horizontal Scale to 1%. So really tiny
03:42and very, very, very narrow. It's almost completely gone now. But there is one
03:47more thing I would like to do and that is set the Character Color to None. It
03:50will fill it with none. And something that's filled with none, you simply
03:54cannot see it at all. That is going to make it completely disappear.
03:58Because the Preview checkbox is turned On, I can see that immediately all of my
04:02Saturdays have become abbreviated Sat. The urday is gone. Click OK. And we can
04:08test this out. I'm going to select this word Thursday and change it to Saturday
04:12and I'll type the letters, but as soon as I type the Y it disappears. Because
04:17the text really is there, but it's disappeared with our GREP Style.
04:22Disappearing text isn't something you need to do everyday but when you need it
04:26GREP Styles and the GREP Find and Change are there for you.
Collapse this transcript
Going Further
More resources
00:00To paraphrase the wise sage Adobe Wan Kenobi, learning GREP is a journey, not a
00:05destination. Fortunately, there are many ways to learn more about GREP and my
00:10favorite way is to surf right on over to InDesignSecrets.com/grep and see what's there.
00:15The GREP page of InDesignSecrets.com lists a whole bunch of resources
00:20that you are going to want to know about, like books and websites,
00:23other pages within InDesignSecrets that offer fun tricks and so on. So check that out.
00:27It also links to other pages on the web that you should know about.
00:30For example, it links right to the search using GREP expression page at
00:34adobe.com. This is part of InDesign's built-in help system and there are a lot
00:39of cool things here. It's a great resource while you are trying to learn GREP
00:42in InDesign. It also links to some cool utilities like this GrepGrokker tool,
00:48which is a Flash app created by rorohiko. It's also called lightningbrain.com
00:52and this is a really cool little tool that will let you learn GREP very quickly.
00:57Another place that you should definitely know about is this website called
01:00Regular-Expressions.info. Lots and lots of cool things about regular
01:05expressions. GREP is the 'general regular expression parser' and that's what
01:10regular expressions is all about. And finally I want to point out that I link
01:14right to this page and one other site that InDesignSecrets links to is this
01:18RegExr page at gskinner.com. This is a really cool Flash or Flex app that this guy built
01:24and it runs inside your web browser. You can also get an Air version
01:29that you can run off your desktop.
01:31But this is very cool because it lets you run GREP right inside your browser to
01:35learn about it and test it. For example, this is just the default text that
01:39shows up here. You can change this to any text you want and as you scroll over
01:43one of these GREP expressions, it tells you exactly what that code means.
01:48You can also learn about all these GREP codes in this list on the right.
01:51For example, if you click on \d, you can see that it says Matches any digit
01:56character. So very, very handy.
01:58You could even change this code to anything you want. So for example, I could
02:01say I want to search for anything that starts with an s and then I'll come over
02:06to this list on that side and see that \w is the one I want.
02:09So I'll double-click on it. That adds it to my list. I already know that I want this to
02:13be a plus sign because I want it to be one or more. But I could pull that out
02:16of this list if I want because this has all those different codes in it. Very,
02:20very handy and I want this to end with the letter g and you can see that as
02:24I have been typing this, different things show up here as highlighted.
02:28And this word here is the only word that fits that GREP expression. So very,
02:32very handy. If I type, let's say, swing, as soon as I finish that G,
02:38it matches the GREP expression so it gets highlighted. Really a very cool system
02:42that this guy has put together. Again, there is the online version and the
02:46desktop version, which is created with Adobe Air.
02:48So tools like this RegExr is a great way to really start learning GREP and
02:53really get your hands dirty with it and then when you are done you can just
02:57copy and paste your GREP expressions into InDesign to use them. With all these
03:02resources we have been looking at, I'm sure you are going to be knocking out
03:05GREP expressions as long as your arm in no time.
03:07So I hope you've enjoyed this little glance at GREP that we've had and may it
03:11help you lay out your pages quickly and efficiently.
Collapse this transcript


Suggested courses to watch next:

InDesign Secrets (8h 57m)
Anne-Marie Concepcion

Learning GREP with InDesign (3h 45m)
Michael Murphy


InDesign CS4: 10 Free Must-Have Scripts (54m 55s)
David Blatner


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 98,468 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,894 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

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.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

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

   
submit Lightbox submit clicked