Lesson 08: Other Expressions

  • Sumo

Quick Takes

TL;DR

Full Text (raw transcript)

PART 1:
In this lesson, we’re going to look at a few other key grip expressions that will come in handy in this example. I have some titles that are in quotation marks. I’d really like them to be italicized. I’ve created a character style for italic, but I need to create a grep expression that will not only italicized the titles, but also remove the quoted text from those titles. We’ll need to create some sub expressions and of course we need to do it in the Find/Change dialog box because we’ll be removing some of the found text.

So I’m going to make sure that my story is selected and then I’m only searching this story and in find what I know that I have quoted text and I have stuff with inside that quoted text. So let’s start with that quotation mark. I’m going to go over to the secret menu, come down to quotation marks and come down to the double left quotation mark. And that’s the expression for a double F quotation mark. Now, I need to tell it to find the characters that come after that quotation mark.

I don’t know exactly what I’m looking for, so I’m gonna use my stuff, expression or any character one or more times. Then I’m going to tell it. I need a closing quotation mark. And we used the double right quotation mark for that now because I’m getting rid of some things and keeping others. I need to give it a sub expression. So what I want to do is I want to find my any character one or more times and put that within parentheses and that becomes some expression group number one or found text number one.

Because what I want to do is I want to tell it. Change it to found text 1. And remember, if we can’t remember what that is. The secret menu will come down a found text number one. So that’s going to find any character. Any number of times between quotation marks and just return the text. But also we need to tell it to change the format to a character style of italic. We’ll say OK to that. And then I’ll search in this story and we’ll just say change all.

And it says two replacements are made while the first paragraph looks great. The Handmaid’s Tale is now a italicized in there. No quotes, but look what happened down here in the second paragraph. Those quotes are still here, as are these opening quotes. Well, that’s because when we said any character quotes or a character in an earlier lesson, I said that grip was greedy and it saw the paragraph as one entity. And that’s exactly what happened. I’m going to undo this really quickly.

It found the first set of open quotes and looked through the whole paragraph and found the last set of closing quotes and an italicized everything in between. That, of course, included the closing quotes and these opening quotes. So what we need to do is use what’s called shortest match and we need to tell it to find the opening quotes. Come along until you find closing quotes. Apply the italic and then continue looking through the paragraph. So let’s go back up to our expression and I’m going to delete the one or more times.

And I’ve told it, look for any character and I’ll come over here to our secret menu and we’ll tell it repeat. And we’ll tell it.

One or more times. Shortest match. And what that’s going to do is give us our plus. But it’s also going to put a question mark after it. Now, I could have manually inserted that question mark as well. Now, let’s say change all. And it makes three replacements. The Handmaid’s Tale, Bladerunner and Do Androids Dream of Electric Sheep are now all italicized and none of them have quotes around them. Sometimes we need to find more than one string of characters or words, but we know exactly what those characters are words are.

We can separate these items using the pipe character or the straight line character. It’s above the backslash key. For instance, in this example, I might want to find all the instances of grilling, boiling, baking, roasting, frying. I want to find all these cooking terms and I want to highlight them in some way so I can type them all out and put this pipe character in between them. So it finds all the occurrences of that. So let’s select this frame search by story and I’ll say find next, find next, find next.

And it finds all those words. You notice, however, it didn’t find the word baking at the beginning of the sentence or the word frying or boiling. And that’s because the way I wrote this is all in lower case. So we’ll come back to that in just a moment. Here’s another example. Let’s say we want to look at any time any of these Acme products are shown and do something to them. We’ve got rockets’ Keys, dynamite in anvils.

Notice how this has two words. It’s going to take everything on either side of these pipe characters.

Select this frame. Just look at the story and say, find next. Find next and find next. Now, what if you wanted to find the word Acme? Let’s put Acme at the beginning here.

We’ll do the same thing. We’ll search on this frame by the story and say, fine, next, find next and find next. You notice it only found Acme when it’s next to rocket skis because again, it’s taking everything on either side of that pipe character. If we wanted it to find Acme anvils, Acme Dynamite and Acme rocket skis, we need to use some sub expressions. In this case, we would take the word acme and let it stay as is, and we’re going to offset this entire group of either or expressions.

So let’s search again on this frame. Say find next, find next and find next. Jumping back to our example with cooking expressions, we want to make sure that we get all the instances of these words, even if they start with a capital letter. Now, I could put boiling with a capital B and boiling with a lower case B and have those B, two separate items. But the only thing that’s different is the upper case or the lower case b.

So I can actually offset that into a sub expression. So let’s go ahead, do that. We’ll do it for boiling and baking and you do it for all the words, especially if you think they might appear at the beginning of a sentence. So I’m going to put these in parentheses. I’m going to put B. I’m going to use the pipe character to say it also might be an uppercase B and then enclose that. So now whether it starts with a lower case B or an upper case B, the word boiling should be found.

Let’s do the same thing for baking.

And you would do that for all the words. So let’s search that story. Find next, find next. Find next, fi next. Now it finds all instances, whether it’s at the beginning of a sentence or not. One thing to keep in mind with these either expressions is how it’s going to grab the expression you’re looking for. If I’m looking for grill or grilling, I don’t want to put it in this order. Grill and grilling, because when I do that and I say find next, it will find the grill in the word grilling.

And it will continue on. It’s never going to find that weird grilling. So when you’re working with something like this, you want to make sure that you use the longer or more inclusive word first. So put grilling and then grill. And now what will find both expressions of that word? You’d have the same thing with this cook. Cooks and cooking. You would want to put it cooking cooks and then cook.

PART 2:
The next thing is character classes, character classes are sort of like wild cards, but you get to decide what goes in them. Let’s take a look at why you might want to use a character class. You may want to create a more inclusive wildcard. For instance, if you want to find not only any lower case or any upper case characters, but any of either, you could create a character class. In fact, InDesign has one built in the any letter.

wild-card is actually a character class. You’ll notice character classes appear in square brackets. You can find several characters all at once by listing them inside a character class. For instance, maybe you want to find all your lowercase vowels ac. I own you. You would just list them inside there. Now when I do a search, find next, find next. It just finds all the lowercase vowels in my text. If I wanted to find all the uppercase ones, I would also add those.

You can also find ranges. So, for instance, if you wanted to find any digit 0 through 9, you’d just type inside your square brackets zero, dash nine.

Now, the dash in this case isn’t seen as a dash because it comes between two numbers. It knows it’s a range. Same thing if you put it between two letters, A through Z. And let’s also do the capitals A through Z. If you need to look for an actual dash, it needs to appear as the first character in a character class so known as they find next fi next. It goes through and it finds each character, whether it’s a letter or a number.

But what if I want to find the entire word or an entire digit or date in this case? Well, I need to tell it one or more times because right now it’s finding each individual character. So let’s select this frame and now tell it, find next, find next. So now it finds whole words and entire numbers as well. Now you notice if you put zero to nine in a character class that finds any digit. So it does the same thing as backslash D.

There are times when you’d want to use one over the other. So let’s do a search on any digit one or more times in this particular story. By next.

By Nag’s for next. Whoops. That’s not what I was expecting to find. I wanted to find the whole number.

I need to add one more item inside this search inside my character class. I also needed to find a comma. So now it’s going to find any digit or a comma, one or more times and in multiple instances. So let’s try that again. We’ll say find next fi next fi next fi next. And that’s a great way to find any number, no matter the size. However, it is looking for a comma. So if you’re doing a search on text that also has commas just as part of the text.

It will find that as well. So again, you have to kind of know what’s inside your text. Or we can narrow our search to something that we know only has numbers in it. You can also find negative values, that is expressions that find text that is not with wildcards changing case will negate their value. So if you want to find everything that is not an upper case character, not a lowercase character, not a digit you would use backslash uppercase U, backslash uppercase L or backslash uppercase D.

If we look for backslash uppercase D, it’s going to find everything that is not a digit. Let’s start here. We’ll say fine. Next fi next. And it’s going to jump over all of those digits. In a character class, you can negate the entire character class by putting a carrot symbol at the beginning. If it appears anywhere else in a character class, you’re actually just looking for the carrot symbol. So if you wanted to exclude a single character from your search, you would just need to put it in a negative character class.

Let’s look for anything that is not a digit. Again, we could have done backslash uppercase D. We can also put inside a negative character class carrot 0 through 9. If we want to find anything that is not a lowercase vowel, we can take that same E IOU and then just put a carrot at the beginning. So now anything that’s not a lowercase vowel will be found. Sometimes it’s easier to say what something is not than saying what it is.

There’s a lot of expressions that you’ll use when creating grep, but these are a few that you can actually use as nice building blocks to get started on more complex expressions.