Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Creating "or" conditions


From:

Learning GREP with InDesign

with Michael Murphy

Video: Creating "or" conditions

The next metacharacter we're going to look at is grouped under the Match submenu. The options in this group are among the most powerful, complex, and abstract metacharacters you'll use when you work with GREP. They handle everything from imposing conditions on your expression, to isolating smaller parts of a larger expression, to defining a custom set of valid matching characters. We're going to start with the simplest of all of these, the Or metacharacter. I'm zoomed in on the top part of page 8 in this document and my cursor is within the body text.
Expand all | Collapse all
  1. 1m 33s
    1. Welcome
      1m 4s
    2. Using the exercise files
      29s
  2. 7m 56s
    1. What is GREP?
      1m 53s
    2. Text searching vs. GREP searching
      2m 35s
    3. Working with GREP and InDesign
      3m 28s
  3. 46m 4s
    1. Using metacharacters, the building blocks of GREP
      6m 37s
    2. Escaping out metacharacters
      2m 49s
    3. Building with wild cards
      9m 9s
    4. Understanding undocumented wild card "opposites"
      3m 11s
    5. Specifying locations
      7m 4s
    6. Learning the undocumented location metacharacters
      4m 45s
    7. Using repeat metacharacters and defining the shortest match
      5m 45s
    8. Specifying exact matches and ranges
      2m 52s
    9. Finding content that doesn't exist with zero functions
      3m 52s
  4. 43m 26s
    1. Creating "or" conditions
      5m 24s
    2. Building subexpressions
      5m 52s
    3. Using character sets to create custom wild cards
      7m 3s
    4. Using negative character sets
      3m 2s
    5. Finding around text with lookbehind and lookahead
      8m 1s
    6. Building with modifiers: Case sensitivity
      4m 0s
    7. Building with modifiers: Single-line and multi-line
      3m 10s
    8. Using InDesign-compatible Posix expressions
      6m 54s
  5. 49m 18s
    1. GREP styles vs. nested styles
      6m 10s
    2. Styling specific words or phrases
      3m 18s
    3. Describing inconsistent text
      6m 59s
    4. Describing and styling prices
      6m 55s
    5. Applying multiple character styles to the same text
      6m 8s
    6. Describing and styling email addresses
      10m 48s
    7. Dynamically fixing orphaned words with GREP
      9m 0s
  6. 33m 30s
    1. Adding more to the mix: GREP Find/Change
      1m 41s
    2. Understanding queries
      8m 20s
    3. Using formatting and styles as Find/Change criteria
      5m 20s
    4. Preserving and recalling using subexpressions
      7m 49s
    5. Backreferences in search queries
      3m 8s
    6. Cleaning up text with GREP
      2m 45s
    7. Creating a GREP-based text cleanup script
      4m 27s
  7. 43m 45s
    1. Describing imported spreadsheet data
      6m 56s
    2. Rearranging imported spreadsheet data
      7m 17s
    3. Applying styles and formatting with GREP
      11m 14s
    4. Describing and standardizing phone numbers
      9m 20s
    5. Inserting anchored objects with GREP
      8m 58s
  8. 27s
    1. Goodbye
      27s

please wait ...
Watch the Online Video Course Learning GREP with InDesign
3h 45m Intermediate Nov 18, 2009

Viewers: in countries Watching now:

Learning GREP with InDesign decodes the language of GREP for InDesign users. It shows how this versatile tool can be used for describing text, which can speed up or automate everyday formatting tasks. InDesign expert and graphic designer Michael Murphy introduces the basic concepts of GREP, and shows how to build powerful expressions using metacharacters. Michael also explores many of the little-known features of GREP, explaining how GREP styles and Find/Change can be used to rearrange data and dynamically format text. Exercise files accompany this course.

Topics include:
  • Using metacharacters, the building blocks of GREP
  • Describing text that may not exist with zero operators
  • Applying multiple character styles to the same text with GREP styles
  • Eliminating orphaned words at the ends of paragraphs
  • Preserving and recalling subexpressions
  • Customizing a GREP-based text cleanup script for long documents
Subject:
Design
Software:
InDesign
Author:
Michael Murphy

Creating "or" conditions

The next metacharacter we're going to look at is grouped under the Match submenu. The options in this group are among the most powerful, complex, and abstract metacharacters you'll use when you work with GREP. They handle everything from imposing conditions on your expression, to isolating smaller parts of a larger expression, to defining a custom set of valid matching characters. We're going to start with the simplest of all of these, the Or metacharacter. I'm zoomed in on the top part of page 8 in this document and my cursor is within the body text.

So my Body Text style is highlighted in the Paragraph Styles panel. I'll right-click on the Style Name, choose Edit Body Text, and I am going to go to the GREP Style area to create a new GREP Style. From the Apply Style menu, I'm going to choose the existing character style, Red. That just highlights text and applies a red color to it. In the To Text field, by default, any digit one or more times is selected, but there's no effect on the page, that we can see, and I am just going to clear that right out. So now, I'm starting clean and I want to use the Or metacharacter in a practical situation.

What I want to actually describe is 'his', and then from the Special Character menu, go to Match>Or, which puts in the Vertical Slash character, also called the pipe. And on the other side of that, I'm going to type 'her'. So basically, I've written an expression that says his or her and applies a red color to any text that matches. Let's click off here, and you can see that's what happens on the page. I get the 'her' in the word 'there', also in the word 'there' here, but 'her' and 'his' as whole words, the 'his' in 'this', the 'his' in 'Whispered'.

So I've successfully matched his or her, but I haven't matched whole words. If I want to limit my results on the page to only instances of his or her that are whole words, and not have any partial word matches, I need to surround each word with a word boundary location metacharacter, which we've seen in a previous movie. So I'm going to go back and modify this expression. I'm going to put my cursor right at the beginning of the expression before the H in his, go to the Special Characters menu, down to Locations, and I am going to choose the Word Boundary location metacharacter.

That puts a \b before the h in His. I'm also going to put one at the end of the word, after the S, another one before the H in her, and after the R in Her, and I did that simply by copying the first word boundary metacharacter, and pasting it in where I needed it, throughout the expression. When I click off, you can see that I've successfully matched just a whole word His or Her in this document. I'm going to clear this out, and let's try another example, using the Or metacharacter.

On this page, there are a few Knights of the Round Table mentioned and I want to call out those names, also using the Red character style that's already selected here. In the To Text field, I'm going to just type in static text, the word Sir, and I'll type space and if I click off, you can see that highlighted on the page here before Sir Galahad, Sir Launcelot, Sir Kay, and in other places. If I wanted to highlight Sir Kay, or Sir Launcelot, or Sir Galahad, you might think that I could type in Sir Kay, go to the Special Characters menu, and choose the Match Metacharacter Or, and then just type Galahad, then another Or metacharacter and Launcelot( Sir Kay|Galahad|Launcelot).

So now I'm saying Sir Kay, or Galahad, or Launcelot. Let's see what happens when I click off on the page. Well, I've matched exactly what I've described, but it may not be what I intended. I wanted to highlight Sir Kay, Sir Galahad, and Sir Launcelot. But instead, I described Sir Kay, or Galahad, or Launcelot, without the Sir before them. The Or metacharacter considers everything that proceeds it to be one choice, everything that follows it to be another choice, and it goes as far as it has to go.

So it looks at Sir Kay as one thing, Galahad as another, and Launcelot. The Sir doesn't get appended to the other Knight names. So, this has to be described differently. So, one way to fix this is to go in to each part of this expression and add Sir and a space before each name. Now, each choice, this, or that, or the other is entirely specific. So if click off, it matches Sir Galahad, up here, Sir Launcelot, Sir Kay, and any other instances of that throughout the text.

The problem is this is not the most efficient way to do this. It's a little bit cumbersome. It takes a little bit longer, and it makes for a longer expression. One of the problems with working with GREP in InDesign is that you only have this amount of space in the field, either here in GREP Styles or in Find/Change, to type your full GREP expression. If the expression starts to get longer, it scrolls over, and it becomes a little bit more difficult to look at the whole thing at once, and work with it, towards the far end of the expression.

So we want to write this a little bit more efficiently, but in order to do that, we need to use something that's called a sub-expression, and we'll cover that in another movie.

Find answers to the most frequently asked questions about Learning GREP with InDesign .


Expand all | Collapse all
please wait ...
Q: In the “Dynamically fixing orphaned words with GREP” tutorial the author uses the term:
(?<=\w)\s(?=\w+[[:punct:]]+$)
In an earlier course the author described the + (one or more) modifier as unusable in a lookbehind or lookahead i.e. (?<=.+). What's the difference here?
A: The limitation mentioned in an earlier movie referred only to positive lookbehind and negative lookbehind. I was able to use the one or more times (+) metacharacter in the positive lookahead portion of the expression because that limitation doesn't affect either positive or negative lookahead. It's only when looking backward that GREP ignores the repeat metacharacters.
 
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.


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 Already a member? Log in

* Estimated file size

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 Learning GREP with InDesign.

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


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

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 ?

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:

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.