Lesson 05: Find by Location

  • Sumo

Quick Takes

Seach by location

  • access via Location sub-menu of the secret menu
  • beginning of paragraph ^
  • end of a word \>
  • end of story \Z (not in secret menu)

Search an expression as a whole word only

  • word boundary \b
  • can enclose a word or phrase with \b at beginning and end
  • same as using \< and \>

Use “lookarounds” to search in relation to something else

  • lookaheads look to text following a given pattern
  • lookbehinds look to text preceding a given pattern
  • there are positive and negative to each (is there/is not there)
  • ex. finding cents in prices uses a positive lookbehind to find a decimal point before the pattern of any two digits

Full Text (raw transcript)

When searching for text in InDesign, grep is known as greedy, and that just means that it wants to see each paragraph as a whole when searching. It basically sees each paragraph as its own entity. But to get her search more focused, we can use expressions that indicate where the expressions should be found. Luckily, most of the locations that we need are found in that secret menu. So we’ll go to the secret menu and scroll down to locations and the first one will take a look at is the beginning of the paragraph and that gives us our Kara character, which is the beginning of the paragraph.

When we build this expression, we want to build it in the order. It’s going to appear so because we’re telling it beginning of the paragraph. That’s obviously where we need to start our expression. So at the beginning of the paragraph, what do we wanted to find? Well, why do we tell it to find the first 10 characters? That way we can use some of the expressions that we’ve already learned. So at the beginning of the paragraph, I would like any character.

So I use the period because remember, that’s going to give us anything but a hard return. And then I want to tell it exactly 10 characters. So I’m going to put 10 in the curly braces. Now select this text. Make sure I’m only searching this story until it find next. Find next and find next. So it jumped down and showed us the first 10 characters in every paragraph. Another location that we can find is the end of a word.

So I put an end of the word, that’s the expression for that can ease my back arrow keys and I’m going to tell it what I’m looking for. And I noticed they have a lot of ING words in here, so let’s find all the words that end in I N G. So I i n g. And then the end of the word expression. Find next, find next, find next. Got a lot of them. But you’ll notice one of the things that we didn’t find was this word ingredients.

And that’s because the ISG doesn’t come at the end of the word. So it doesn’t fit the pattern. Let’s find wherever there’s a period at the end of a story, maybe we want to change it to something else. We want to style it in a color or something like that. I’m going to go to my secret menu, come down to locations and I don’t see. End of story. For whatever reason, this isn’t included in InDesign secret menu.

But there is an expression for it. So what I want to do is come up here and I want to tell it. Find a period. We need you to backslash period, because we’re finding a literal period followed by the end of the story. And that’s backslash Z. Now I did a capital Z. This is an oddity in that capital Z or Lower Casey both work for this expression. So I’m looking for a literal period just before the end of the story.

Soul search on that and say find next and it finds the period right at the end of the story. Another location might be something along the lines of just find when a word appears by itself as opposed to part of another word. For instance, we have this word grill, but it also appears as part of grilling. If we’re looking for it just when it’s by itself, we need to isolate that. And we’re going to use a word boundary.

If you’re used to using the find change with the text tab, you might be familiar with this little icon where it’s as whole word. We’re going to do the same thing in grep. We just don’t have an icon for it. We have to build that into our expression. And this one’s located also in the secret menu and it’s listed as word boundary as just backslash B. Now I want to put this at the beginning and the end of the word.

So I’ll just put it there twice. Then I’ll wedge the word in between. So I’ll type in grill. So now we have grill surrounded by these word boundaries. And when I do a search, it only finds the word grill and not grill when it’s part of a longer word. One thing you might notice is that this sort of says beginning of the word and the end of the word that backslash B. And in fact, it does exactly the same thing as choosing beginning of word.

And end of word. So you can use those interchangeably. Sometimes the pattern only works when it’s near or not near something else. I know that’s a little confusing. Let’s look at this price that’s here. We’ve got this price and I want the nine nine or anything that’s after the decimal point to be superscript. So I need to find that now to do that. I can use what’s called a look around. There are actually four of them. They all live in that secret menu down under match.

We’ve got four look arounds at the end. There is look aheads and look behind’s and there’s a positive and negative of each positive negative. It’s pretty self-explanatory. We’re either looking for something that is there or isn’t there. Look behind and look ahead is a little more confusing. So let’s go back to this example of this ninety nine. What I want is I wanted to find two digits and then look around and see if it comes right after a decimal point.

And if it does, then I want to do something to it. How I think about it is if I were walking through the woods on a path and I see something and I want to look behind at something I’ve already passed. So I kind of think of it as wandering through the sentence.

I’m walking along and suddenly I hit two digits so that these two digits here, I’m going to look behind and see if there’s a decimal point. If there isn’t, I’m going to continue on. So we hit the ninety nine and I look behind and say, yes, there is one, do something to these digits. So that’s a positive look behind. Now I know that’s confusing.

You might have a better way of remembering that or you may have to just try each one until it works for you. So let’s find this 99 after decimal point. I’m going to go to the secret menu. Come down to match and remember, it’s a positive. Look behind. That’s the phrase for positive look behind. But I need to tell it what it’s looking behind for. So I’m gonna use my back arrow keys and get sort of inside that expression.

And I wanted to look for a decimal point backslash period. So I’m looking for a literal period character. Then I’m gonna come outside that expression and put what it is that’s supposed to come after that decimal point. In this case, I’m looking for two digits. Gonna do backslash D twice. I could also do backslash D and two in curly brackets. So I’ll choose the story and say find next. And now it found those two digits. And then we can do something like make that superscript.

Now let’s do a look ahead. I want to look ahead to see if any words are followed by a question mark. So, again, I need to put this in the order that it appears in. I wanted to find a word. So I’m going to do backslash W, which is any word character. So that’s any upper or lower case. Any digit or the underscore any word character would do one or more times because I don’t know how many characters in each of these words.

And now I wanted to look ahead to see if there’s a question mark. So I’ll go to the secret menu down to match. I’m doing a positive look ahead. And then I need to tell it what it’s looking for. Back inside the expression I’m going to do backslash question mark, because I’m looking for a literal question mark as opposed to this, which is a special expression, just like the story until it find next. And it finds each word that appears before a question mark.

I’m going to do one more look around and we’re going to do a negative look behind. So basically, I want to tell it, find a word when it doesn’t come right after something else. So in this case, I have the word info down here. Maybe I want to find wherever info appears, but I also have it here as part of what looks to be like a u._r._l. I’ve got elementary dot info and I don’t want it to find it when it’s part of that.

So I could tell that it fits the pattern. If it doesn’t immediately follow a period. So I’m doing a look behind. I’ll start with that match. And it’s a negative look behind in this case. There’s my expression for that. Go inside the expression. I’m looking for a period, a literal period, backslash period. And then I’ll just type the word info and we’ll search on this story and we’ll say fine next. And it only found it down here.

Now, one have followed that period. In the next lesson, we’ll learn what to do with the text that we find with our grep expressions.