Skip to main content

GREP Styles

Lesson 8 from: The Complete Guide to InDesign Styles

Erica Gamet

buy this class

$00

$00
Sale Ends Soon!

starting under

$13/month*

Unlock this classplus 2200+ more >

Lesson Info

8. GREP Styles

Lesson Info

GREP Styles

- [Erica] One of the things that we can do... This is a big scary word. Everybody gets freaked out about it because it's an acronym. I'm not going to go to this is definitely a... I've done a whole day class on GREP before and that's what it is, GREP. Everybody wonders what it is. It sounds scary. I always joke that it sounds like some disease you really don't want to get. You've got the GREP and I joke that it's called, in my world, Unicorns and Rainbows because people would use it a lot more if it was called the Unicorns and Rainbows, but it is called GREP. It comes from the programming world. We're not going to worry about why. What does it do, though, for you? Well it basically lets you do things like if you have a phone number that's 10 digits long and it's just 10 digits but you need to put in dots in between or dashes or maybe you've got phone numbers that are formatted in all those ways with parentheses and dots, dashes and 10 digits crammed together, you need all those, but yo...

u need them all to be formatted the same way. You can create what's called a GREP expression and that's actually what the R E in GREP stands for is Regular Expression. You can create an expression or I sometimes call it a code which I know is completely wrong, but I don't care. I just care what InDesign can do for me with it is I can just set up a little formula and say do that and it will change those 10 digits, however they're formatted, to exactly what you need. So think what that would mean, especially for the person that has this catalog that we were just talking about you know they have this catalog that they need formatted. What if those all had phone numbers formatted in five different ways and you need to standardize that formatting? You can do that with GREP. Well, GREP lives in two places in InDesign. And one of the places is in Styles, in Paragraph Styles. So in Styles, here's something that we can do. If you have this 14.95 written as such and you want the cents and the dollar sign to be superscripted, you can do that with GREP. Basically, I can build that into a style and I have a style called prices. I'm just going to click that and suddenly, it's formatted for me. Now yes I realize that the dot is still there. There's a way to get rid of it but it's kind of a workaround. So just pretend that that's exactly how you need it formatted. But think how easy that was that that fit right in. And so if I am working along and I've got some prices here and I tell it, and I called it prices. I might actually bake in this little formula to my body text so that as I'm typing along and I encounter prices or something that I've defined as a price, it will automatically change for me. So if I say the price is and I hit my dollar sign, it automatically superscripted it for me. I didn't have to do anything for that. It's built in. And then I can say $123.50... Nothing's happening yet. Five cents. Boom it just automatically did that for me. And it's magic. That's how it works. They went I hit the period, it's suddenly back to you know it's back to regular. So we'll do that and we'll say also available for more money for, let's say, $150. There's something special about that. Boom, $150. All right so as I'm typing, this is automatically happening so I've got that built in and that's through the power of GREP. And I'm going to show you really quickly kind of what's involved but I'm not going to go into all the reasons that's there but just sort of you can kind of start thinking about what GREP can do for you. And basically, in a Style what GREP can do, and they work differently whether it's in a Style or we're using Find/Change. But in Styles, basically, anything that you could apply a character style to. So for instance, I have a character style set up that's called Cents and one that's called Dollar Signs. And the things that I've defined in there in cents is I've told it superscript. So all I've done is come in here to the basic character formatting and said superscripting and then in the Paragraph Style, I've told it every time it sees a dollar sign, apply the character style. So it's basically as if I had selected this and said apply this character style. There it is. It went ahead and applied that to it. So it's doing that automatically for me. I've got another one called Cents. Also I've got Cents and Dollar Sign and basically here's a little secret. These two are actually the same. All I've done is apply superscripting, but I have them broken out so you can see the two ways that I've had to define this. So basically I built that in. How did I do that? Let's go back to the Paragraph Style called Prices and there's a thing called GREP Style. It's about halfway down and when you first see it, it is completely blank. There's nothing in here. You have to click New GREP Style and as soon as you do that, you get this here and you get this little formula that you don't need. It's like a sample formula that's there just delete it. But what we've done with it. I'm actually going to delete this whole style. So all I've done is say apply a character style. And I'm going apply the dollar sign to something. And in this case, you've got to learn a lot of different little expressions. So how we express a dollar sign in GREP, when I'm looking for it, is backslash dollar sign. And again I'm not going to go into a lot as...I do have a cheat sheet on my website. We can put that if you want in there. I'll put the whole link to it because I don't know what it is, but it's on my website, ericagamet.com or you can look up GREP cheat sheet. It's there. And so I have things like this like these wild cards, and if you can't remember some of them, they actually live in the secret menu over here. A lot of them do. So in this case, though, I'm looking for a dollar sign so I basically said anytime it sees a dollar sign, apply the character style dollar sign. And there's something I've done here. I'm not going to go into what all this means. I know it looks overwhelming. But basically what I've said is any time it sees two digits in a row, look just before it, and that's what all this gobbledygook here means, look before it and if it is preceded by a period, then do something to these two digits. All right? So it's going along and as soon as it sees two digits and says, "Hey what was just before it? Is there a period?" No, there's not. Like here in this 123, there's not. So it doesn't do anything to it. But as soon as it says, "Oh, here's .99, Oh that 99, just before it there's a dot, so you want me to take that 99 and apply the paragraph or the character style Cents to it." So hopefully that kind of makes sense, but I built that into the style so that I don't have to think about it. So just when you start thinking about GREP, should I use this? How can I use it? In a style if there's a way that you could you know if it's a paragraph style and if there's something that you need to apply a character style to and it fits a pattern that you can express with GREP and figure out a way to express that pattern, then you can apply that style to the text it finds. So basically finds patterns of text and styles that with a character style, and you build that into your Paragraph Style. Like I said, you can also do it in a Find/Change. Find/Change gives you so much more options. You can rearrange and add things and subtract things and all that. But in Styles, this is someplace I use it a lot so that because with Find/Change, you have to keep doing Find/Change. You have to keep running it. With Styles, you put it in there and boom, boom, boom it's ready. And I'm going to show you one really cool tip that you might want to put into a style. And again you could do this with no document open. Build this into your basic paragraph style. And then every new style you create from that point forward will already have this GREP style in it. And this is to get rid of orphans. So like those little runts, orphans, widows the bit at the end of the line. And that's what we're going to do. We don't want to have fewer than let's say 10. You have to kind of choose how many we think is acceptable. How many characters you can have at the end of the line before you realize it's too short of a line. We're going to go with 10. You might need to change this from time to time. Let's just fill this with some text. Let's not fill that with text. That is not my keyboard shortcut on this computer. I'm going to go ahead and fill that with some placeholder text and I'm going to make it just a little bit bigger so we can see it. And I look right now and look at that. There's this word at the end of the line. That's too short. I don't want that. I want to make sure that that doesn't happen. So what I need to do is create a character style so I get nothing selected. I'm going to create a brand new character style, and I'm going to call this No Break, and I'm going to go over to the Basic Character Formatting,and all I'm going to do is select No Break. All right? So I've turned it on. I've told it...and the No Break is something you can do. You could manually select words until it no breaks so it never actually breaks that across a line. So I've got that set up as a character style. Now in my paragraph styling which I need to create, I'm going to say that this is my body text. So I want to create new body text. So I have that built in here. That's body text. And I want to build a style in there that says never let that last line break. So basically what I want to do is assign the last 10 characters. We have at least 10, right? Or less than 10. One, two, three, four, five, six. Okay, so we're good. So I want to assign that and the other thing I want to do in the character style before I forget. In my no break in this setting, I'm going to change the color just so we can kind of see where it's being applied. Obviously, I wouldn't normally do this. I would just have no break on there. So anyway, I'm going to go ahead and set that up and I want to build into this style. No Break. So I want to go to my Paragraph Style This is Body Text. I want to build into Body Text GREP style, create a New GREP Style. I want to apply the No Break Style to the last 10 characters of every story or every paragraph, I mean. So I'm going to do a little thing. I'm just going to show you what it is. You guys can break it down, read it later, look at my cheat sheet and see what it is that I've actually done. I'm going to apply it to any character. That's what the period means. Any character. I'm going to tell it 10 times. I'm going to put 10 in these little curly brackets and then I'm going to tell it at the end of a paragraph which is the dollar sign I believe. Let's do that. Let's try that and I can come over here and just click off. And you notice as soon as I did that, it added some more text. And I can see where the last 10 characters which includes a space are actually in red. I just do that so we can see that, but you can see that the last 10 characters have that No Break applied to it. So if I shorten this up, and we get squashed down, it never ever lets me have fewer than 10 characters on that line. I'm just shortening it up and it never lets me have fewer than that. So that's one that you can build in. Like I said you can do that with no document open. Build it into your basic paragraph. Every paragraph that you create in any new document will automatically have that GREP code already built into that style and you'll never get stuck with those ugly widows, orphans, runts whatever we want to call them at the end because I can never remember which is which. So that's just a couple quick things just to kind of wet your whistle a ittle bit and say, "Oh I like that idea of GREP." So always be thinking in patterns. If you can define a pattern, find a pattern of text and then do something with that text. And in Styles, it means add a character style to it by finding that pattern. So that was my little extra thing I want to make sure that we got in there. - [Man] Yeah, have a question about this. Sarah asked, "Can GREP be used for superscript superscript for words like 1st, 2nd, etc.?" - Not...well you could, but first, second, third that's really hard to do because you'd have to define a pattern that said this first one is fine followed by a second one that doesn't have it. So doing that is hard. You're actually better off building nested styles into that. So you can do a nested style. You can say you have that for the first word and then the next word it goes back to regular then the next word up until the next word is there so you would do the nested just the same way. That would probably the better way than GREP. GREP is like very less specific. It's sort of like these generalized patterns that are there.

Class Materials

Bonus Materials

Adobe Stock

Bonus Materials with Purchase

Fun Styles
Newsletter Files
Styled Text
Table Styles

Ratings and Reviews

a Creativelive Student
 

Another amazing class Erica. I'm going to have to purchase the one because it's so much cool content I didn't know.

user-8d447e
 

Lots of good information to make using InDesign efficiently. Thank you for this!

DOlores RUsso
 

You are the consummate online teacher! And as you know, teaching teachers is the worst ever...and I can I honestly say (as a photoshop teacher) , I love how you are so organized and you just keep going. We are focused!

Student Work

RELATED ARTICLES

RELATED ARTICLES