New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

InDesign: 10 Things to Know About GREP
Illustration by John Hersey

6. Specifying text location in a paragraph


From:

InDesign: 10 Things to Know About GREP

with David Blatner

Video: 6. Specifying text location in a paragraph

One of my favorite usages for GREP is to apply Paragraph Styles and Character Styles to text in a long document. For example in this file I have some lists, and this list is just not consistent. I guess somebody actually typed 2 and then there is a period, and then a space, but up here there is a bunch of spaces and down here there is a number, a period and a tab. So in some cases there are tabs, in some cases there are spaces. I really wish I could get rid of all of that and just apply InDesign's automatic numbering. That way I know it will be consistent and look just right throughout the document.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
InDesign: 10 Things to Know About GREP
1h 8m Intermediate Apr 30, 2009

Viewers: in countries Watching now:

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
Subject:
Design
Software:
InDesign
Author:
David Blatner

6. Specifying text location in a paragraph

One of my favorite usages for GREP is to apply Paragraph Styles and Character Styles to text in a long document. For example in this file I have some lists, and this list is just not consistent. I guess somebody actually typed 2 and then there is a period, and then a space, but up here there is a bunch of spaces and down here there is a number, a period and a tab. So in some cases there are tabs, in some cases there are spaces. I really wish I could get rid of all of that and just apply InDesign's automatic numbering. That way I know it will be consistent and look just right throughout the document.

So how can I do that? Well, I'll open up the Find/Change dialog box with the Command+F or Ctrl+F on Windows and I'm going to type in a GREP code that defines this pattern. This pattern is going to be a digit. So I know that's /d and I'm going to say -- actually there might be more than one digit because maybe it's one digit or maybe it's ten or eleven, maybe it's more than one digit, and I think that it has a little dot after it. Most of these seem to have a period, but I know that the period code means any character. So I need to escape it out.

I will press the left arrow key on my keyboard and put a \ before it. So this means a period itself, look for that actual character. Now it might be there or in some cases it might not be there. Maybe they forget to put in. So I'll put a question mark. So that says this period may or may not be there. Now their may or may not be a space there. So I'll do a \s, and there is probably one space or two spaces, or I don't know how many, let's go to the fly-out menu and choose Repeat Zero or More Times. So it might be there or it might be one, two, three... we don't know, and that's the asterisk code.

So that's looking pretty good. That seems to define the code we are looking for. Let's try it. I'll click Find and we can see it found that 5. That's good. Find Next and that seems to work there. Uh-oh! That's not working at all. What happened? It found a number right in the middle of a paragraph. Well, it was a number and it was followed by a space, but that's not something we want to find. We need to define the GREP code even further and specify exactly what we are looking for. In this case we need to tell the GREP code to only consider numbers at the beginning of a paragraph.

So I'll place the cursor before that initial backslash. I'm going to go out to this little @ sign fly-out menu and I'm going to give it a Location. The Location pop-out menu offers me five choices, Beginning of Word, or End of Word, or right out of Word Boundary. In this case we want to use Beginning of Paragraph and only Beginning of Paragraph, which is the caret symbol. So this pattern has to be at the beginning of a paragraph. Let's try it out. Click Find Next, and it finds it, click Find Next, and it finds it. So this seems to be working just right. Now what do we want to do to this GREP pattern.

Well, we want to apply a paragraph style to it. So I'm going to do click down here in the Change Format field, brings up the Change Format Settings dialog box and I'm going to say I want to apply my numbering list Paragraph Style to anything that matches this style. Let's go ahead and click Change All and see what happens. It went through my whole document and it seemed to work but I didn't quite work the way I wanted it to. It applied the style, that's great, but it did not get rid of the text that it found. I still have this 8 period space, space and so on.

So I wanted to get rid of it, and I left to Change To field blank so you would think that it would delete it, right? Well, true except that there is this little i here. That i means that this formatting applied to it and when you have Find What filled, Change To blank but the i here, some format applied to it, that means go ahead and leave the text there. So in order to make this work I need to do one more little thing. I need to search for one additional character. I'm getting ahead of myself here a little bit but I'm going to let you in on a secret and that is, I can take text from here and put it down here if you put it in parenthesis. And the text that I'm going to take is any single character. That period means any single character that it finds.

And because it's in parenthesis I can put that character down here with a special code and that code is $1. Now dollar sign up in the Find What field means it's a Location tag, it means only find it at the end of a paragraph. That's what dollar sign means. But dollar sign down here in the Change To field means something very different. It means take whatever was up here inside this parenthesis and put it down here in the Change To field automatically. All right, so I'm going to Undo this, Command+Z or Ctrl+Z to go back to where I was, and now we'll try it one more with this extra code. One more time it's going to search for at the beginning of a paragraph, look for one or more digits followed by maybe a period, maybe not, followed by maybe some space, maybe not, followed by anything. And then take that anything and put it down here and while you are at it format the whole paragraph. Will it work? With one click we can see that it formats the entire document quickly. We have deleted the text that we didn't want there and applied the paragraph formatting.

Now let's take our new found knowledge of setting location to do one more search here. I'm going to delete these and start from the beginning. I want to find only whole words that begin with c and end with e. So I'm going to say c and e, I know that's there. I know that there is any lower case character in the middle so that's going to be \l with a plus. So one or more other characters between the c and the e, but not just any c followed by some letters followed by e. Only ones where the c is at the beginning of the word and e is at the end.

So to do that I place my cursor before the c, I can say at the beginning. At the beginning is going to live in the Locations pop-up menu and we could use either Beginning of Word or Word Boundary, either one works. I'll choose Word Boundary here, and then I'll put another Word Boundary over here. So it says at the Word Boundary start with the c. At the other end of the Word Boundary end with an E. Let's try it. Click Find and it finds Chocolate, Find again, chocolate. Find again, and it keeps, oops. There is another one, starts with a c and ends with an e, but it's not chocolate. So I know that my pattern worked.

If you don't specify a Location code for your GREP code it will find it anywhere, in the middle, beginning, end of a paragraph, you don't know where. But when you put those codes in that's you specify exactly what you want to find and where you want to find it.

There are currently no FAQs about InDesign: 10 Things to Know About GREP.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed InDesign: 10 Things to Know About GREP.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

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.

Sign up and receive emails about lynda.com and our online training library:

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

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.