Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using character sets to create custom wild cards

From: Learning GREP with InDesign

Video: Using character sets to create custom wild cards

The Wildcard Metacharacters we saw in a previous movie, like any digit, any character, and so on, provide a quick convenient way to describe common character types. But you may find yourself wanting to define your own custom wildcards of specific characters to be matched. That's what the next option under the Match sub-menu, Character Sets, allows you to do. I'm zoomed in on the top part of Page 3 in this document, and my cursor is inside of the body text, which is why you see it highlighted here in the Paragraph Styles panel, where I'll right-click it, choose Edit Body Text and go to the GREP Style area.

Using character sets to create custom wild cards

The Wildcard Metacharacters we saw in a previous movie, like any digit, any character, and so on, provide a quick convenient way to describe common character types. But you may find yourself wanting to define your own custom wildcards of specific characters to be matched. That's what the next option under the Match sub-menu, Character Sets, allows you to do. I'm zoomed in on the top part of Page 3 in this document, and my cursor is inside of the body text, which is why you see it highlighted here in the Paragraph Styles panel, where I'll right-click it, choose Edit Body Text and go to the GREP Style area.

I am going to create a New GREP Style to demonstrate how character sets work. From the Apply Style menu, I am going to choose the existing Red character style. That will just color the text red on the page and the default of any digit one or more times is in here. Again, if I just click in there, you'll see that it highlights any digit on the page. That's actually a useful starting off point because any digit means any digit, 0 through 9. But what if you wanted to define only a handful of digits? Let's just say 1 through 5.

One way to do that would be to type 1, the Or metacharacter, 2, another or metacharacter, 3 or 4 or 5 and when you click off, that's what you will match, any of those digits, one or the other. The problem is the Or Metacharacter is neither the best nor the most efficient way to do this. When you use a character set, I'll clear this out here, click off and then go to the Special Characters menu at the end of the field, go down to the Match sub-menu and choose Character Set.

That inserts an opening left square bracket and a closing right square bracket. Anything that exists inside those brackets is part of your character set, so whatever you put in there is designated to be a valid matching character for whatever you're looking for. So within here, I could just type 12345 without an Or metacharacter because within a character set or is implied. Anything in there is a match so 1 or 2 or 3 or 4 or 5. So I'll click off here and you can see that the result is the same as we saw before, without needing the Or metacharacter and just typing in the numbers in succession.

They don't even have to be in that specific order. It could be any random order of those digits. This is still yet not the most efficient way of doing this. Within a character set, there is a way to streamline this even further. I am going to click in here and I am going to select 2, 3, and 4, delete them and replace them with a dash. I'll click off here and you can see that nothing has changed on the page. I'm still only matching numbers between one and five and nothing above that, but I'm doing it by describing it as a range of digits from 1 through 5.

And I can do that from 2 through 7 and click off, and you can see what changes on the page" 2s, 5s, 7s but no 1s, no 8s, no 9s, that sort of thing. So you can describe a very specific range to suit your needs using this and it also works on alphabetical characters as well. So if I typed 'a-z' and clicked off, you'd see I've matched every lowercase letter from a to z. If I only wanted to match a through k, I could just replace that z with a k and I only get letters a through k in lowercase.

If I wanted to match a through k in both upper and lowercase, I would just append A-K after that, within the character set, and I click off and you'll see those matches here. C is colored red, A is colored red, O is not and so on. So this is good for creating a very finite and specific set of characters that you need to match. Suppose, however, you needed to describe an actual dash as part of your character set. That's one of the characters you want to match.

The safest thing to do when you're doing that is to put the dash at the beginning of the character set. For example, if I type 1 through 5 or 1-5 rather, click off. I'll get a range of digits from 1 through 5. But if I want to find a dash, a 1 or 5, I'll cut that dash out of there and paste it at the beginning of the character set. When I click off, you can see what I match. I matched 1. I matched a 5 and then down here, in the word 'forty-eight', I matched a dash.

So, whenever you need to include a dash in a character set, the safest bet is to put it at the beginning of the character set so it doesn't get confused as a range-definer for any alphanumeric characters that might be around it. Another thing to be aware of when working with character sets is that certain metacharacters, specifically the single character metacharacters, like a period for any character, and a question mark for 0 or 1 times, those characters do not retain their meaning when they exist inside of a character set. For example, I'll delete what's in here and click off, and then within this character set, I am just going to type a period, which normally means any character.

But when I click off, you'll see that it's actually only colored periods on the page, in red. It no longer means any character. The same applies for question marks and asterisks and the Plus sign. Any of those single character metacharacters no longer retain their special meaning. I always think of it as a character set is like kryptonite on single character metacharacters. It just strips them off their special powers and they become the normal mild-mannered punctuation marks that they normally are.

Other metacharacters, however, act just like you'd expect them to. If I delete all this out of here and I put in \d for any digit, \u for any uppercase letter, and click off, I match exactly that. They're still metacharacters within there. So if a metacharacter uses the backslash or tilde syntax, and is composed of one or more characters to define a specific character type, that will still work inside of a character set. It's only the single character metacharacters that don't. In fact, there is a character set built into the Wildcards in InDesign's Special Characters menu.

If I delete this, go to the Special Characters menu and go to Wildcards and choose Any Letter, you can see that that's actually a character set. It's the any lowercase letter and any uppercase letter metacharacters enclosed within a character set. It's placed in there as a convenience. It's not an individual wildcard. It's two wildcards built into a character set. So when you need to define several characters as an acceptable match, a character set is the way to do it. Remember though, that dashes can define a range of alphanumeric characters and single character metacharacters lose their meaning inside of a character set and revert to standard characters.

Show transcript

This video is part of

Image for Learning GREP with InDesign
Learning GREP with InDesign

42 video lessons · 12823 viewers

Michael Murphy
Author

 
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

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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
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

Your file was successfully uploaded.

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.