Lesson 07: GREP Styles

  • Sumo

Quick Takes


Full Text (raw transcript)

Up until now, we’ve been working with grep in the Find/Change dialog box, and that’s because it can be easier to create and check expressions as you build them. Also because of the versatility you have with the found text. But in this lesson, we’re going to look at building our expressions into styles. The biggest advantage here is that the styling is built in so that any text that fits our pattern is automatically styled for us. So let’s take a look at some examples of using grep expressions within a paragraph style, going back to our example of prices.

Let’s take a look at how this style is actually created as it is right now. I have a style called body no prices. I have no grep style built into this paragraph style events like this first price and assign a paragraph style body with prices. I notice it automatically gets formatted and because it is a style, if I create another price, let’s make it 12 fifty five. As soon as I hit that five, it automatically fits that pattern and styles it for me.

This is one of the great advantages of building a grep style into your paragraph style. Everything gets styled as soon as you type or assign that paragraph style. So let’s go ahead and add that styling to this particular paragraph style. So let’s go ahead and change our body. No prices and we’ll go ahead and add the price grep style into that. Select all the text. I’m going to go ahead and assign body. No prices because we’re going to change that in just a minute.

Before I do that.

I want to set up a character style called superscript. I already have one here. Basically, I’ve created a superscript style and the only character formatting I’ve assigned is that I wanted to be superscript.

All right, let’s jump back to the paragraph style panel, go into the body, know prices and edit that. I want to make sure my previews turned on so I can see the changes as I make them come down here to the grep style pane and we can see that there are no grep styles applied. Let’s create a new grep style and it’s not readily apparent. But this is a menu and it does autofill with this expression. We don’t need that.

Let’s delete that. All right. Let’s apply a character style of superscript to our text, and the first superscript text that we want is our dollar sign.

So to tell it. Dollar sign. We need to escape that because dollar sign means something specific in grab. So we use a backslash and then dollar sign. Now by clicking down in this area, I can see that the changes have actually been made. It went ahead and superscript at our dollar sign. You can have multiple grep styles built in each paragraph style. Then you don’t need to create one expression that catches everything in the pattern. And in this case, they’re two very separate things.

We’ve got a dollar sign. We’re also looking for two digits when they follow a decimal point. So let’s create that second one new grep style. I’m going to choose that same character style of superscript. Delete the expression that’s already here because that expression was already here. It thinks I want to apply superscript to any digit that I find. That’s not the case. Let’s just delete that and click off. Now we need to tell it what text to assign that to.

Well, because we’re looking for two digits after a period. We’re going to use a positive look behind. So we’ll go down to match. And she’s positive. Look behind. That’s our expression for positive look behind. I need to use my arrow key to get my cursor back inside that expression. I’m looking for a decimal point or a period backslash period gets us a literal period character. Use the arrow keys to get back out of that expression. And now I need to tell it followed by two digits.

I’m Yanni’s backslash D twice. You could also do backslash D and two in curly braces. I’ll click off of that so I can see the changes. I can see that that looks good. So I’ll say ok. Now of course that says body no prices. We would probably want to change that paragraph styles name. Now in this case I made a specific paragraph style just for prices. Now if I wanted prices to automatically look like this throughout my text, I would want to build this grep expression into all of my paragraph styles.

Let’s take a look at a couple more examples. Here’s an example we saw earlier where we wanted anytime the word the Sybase Corporation or just CYPESS appears, we wanted it to appear in our company colors. So we created a character style called Cypess Names, which just has a color applied to it. And I’ve also created a paragraph style called Corporate Body Text CYPESS that already has that grep expression built in. Let’s apply that. Right now, you can just see I have an override, I’m going to clear that by option clicking on the name and now I can see that the Sybase Corporation and also Sybase automatically appears in blue.

Let’s check out that’s created. If I double click on this particular paragraph style and come down to grep style, I could see that I have two different grep styles applied to create that and I’ve actually typed out what needs to be in blue. So I’ve told it apply. The CI was named character style to the text, thus Ibos Corporation. I also have applied the same character style to the text cypess. In the next lesson we’re gonna learn how to combine those and actually create one expression that does the job of both of these.

But for now, let’s keep them separate. So now anytime it sees the Sybase Corporation or CYPESS, it goes ahead and applies that character style. In this example, we have a set of questions and answers from a magazine and we want our questions to be in a different color at the moment. We have these set as two different paragraph styles. Got the question one and the answer and another. But what if we wanted those questions to be run in?

We want them all in the same paragraph, but we still want the questions to be in red. We can do that with a grep style. So right now we can see we’ve got a paragraph style called question and one called answer. Well, let’s run those together. If I make this into one paragraph and assign one particular paragraph style to that, it runs together and we lose the look of the question altogether. What I want is something more like this run in style.

Let’s take a look at how we did that. I’ll come over here to the grep style and I see that I’ve applied a character style called question text and those attributes are just bold and red. Now I have to tell it what to apply that to. Well, the thing that makes this easy is that I have a question mark at the end of that question. Now, if you’re already thinking ahead to what might also fit that, if I have a question somewhere else in this paragraph, this exact expression won’t work, will have to be a little more specific.

But again, I’ve made sure at the moment that I have no other question marks within my text unless it’s that first question in the paragraph. Now we know the first paragraph has the style applied to it. So I’m going to go ahead and delete what’s here and click off of it so we can actually watch it being built. So let’s apply that to the text. Well, we know it starts at the beginning of the paragraph, right? So we’ll put our little carrot, which is beginning a paragraph.

And again, if you don’t remember, you can come over to the secret menu and choose locations and find beginning of paragraph. Now we know there’s a bunch of text. We don’t know what that is or we’re going to use our expression for stuff, which is period plus. And then we know there’s a question mark. Again, backslash question mark. Now, let’s click off of that and click down in this area here and we see that it works just fine.

Now, didn’t style anything else because we haven’t applied that style to any of this other text. So let’s say, OK, and let’s just select this entire frame and apply that answer runnin’ paragraph style. Now, sometimes taking the long way around and creating an expression with grep might not be the best solution. This could also have been achieved using a nested style. I’ll show you how we do that really quickly. I’m going to come into grep style and delete that style.

Now I’m going to go to drop caps and nested styles and do a new nested style using that same character style. I’m going to tell it question. Text up through you have up to her up through the first.

And in here I’m going to type a question mark and you get the exact same results. Where grep style will come in handy is that if there are other question marks in that paragraph and we need to eliminate them, we can get a lot more specific with a grep style than with a nested style. So in thinking about whether or not to use a grep style or using the Find/Change dialog box. Think about how you need to style the found text. And if that styling can be achieved with a character style, if you need to add, delete or rearrange your found text, you’re most likely going to have to use the Find/Change dialog box.

These are all considerations for deciding if you can use a grep style or a fine change will be your chosen route. In the next lesson, we’ll look at some other helpful grep expressions to help you find even more patterns of text.