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

Understanding queries

From: Learning GREP with InDesign

Video: Understanding queries

The idea of search and replace is nothing new. Most of us are familiar with it from applications like Microsoft Word, among others. But InDesign's Find/Change is a far more robust feature that goes beyond search and replace and allows you to build and save full queries. So what exactly is a query? A query refers to every parameter that's established in the Find/Change dialog. Everything that's entered in the Find what field and in the Change to field. Any choices that are turned on or off, like Include Locked layers, Include Locked Stories, Hidden layers, Master Pages and Footnotes.

Understanding queries

The idea of search and replace is nothing new. Most of us are familiar with it from applications like Microsoft Word, among others. But InDesign's Find/Change is a far more robust feature that goes beyond search and replace and allows you to build and save full queries. So what exactly is a query? A query refers to every parameter that's established in the Find/Change dialog. Everything that's entered in the Find what field and in the Change to field. Any choices that are turned on or off, like Include Locked layers, Include Locked Stories, Hidden layers, Master Pages and Footnotes.

Also, any formatting that's been specified as a search criteria and any formatting that's going to be applied as part of the change operation. All of that put together makes up a query. So when you're building a query, that's actually a lot of information if you're using all of those criteria, and it's the sort of thing that you don't want to have to do over and over again. Fortunately, those queries can be saved and reused later. Anything that you find useful enough to search for once you can do again, without having to start from scratch.

I am going to build a query and show you what I mean. In the Find what field, I am going to start a query that cleans up a small problem in this file. I've got a lot of double dashes in the text, like here, and down here. Some of them have spaces around them, some of them don't. It's inconsistent and I want to use proper em-dashes. So I want to do a search and replace that cleans up some of this text. So let's start building this query. These double dashes may or may not have space around them.

So I want to account for that with the \s metacharacter for any whitespace followed by the asterisk, which means zero or more times, just in case somebody typed in two spaces. I'll type in two dashes, and then another backslash, s, asterisk, for any whitespace, zero or more times. That's what I am looking for, and I want to change it to an Em Dash. So I am going to under Hyphens and Dashes to Em Dash and the tilde underscore metacharacter is put in, which represents an Em Dash.

There's one other thing I want to do and that is to modify the formatting of that Em Dash. I feel like the Em Dashes in this particular typeface are a little it too wide. I don't want to go with an En Dash, which is thinner. So I want to tweak my Em Dash with a character style. So I am going to click anywhere in this Change Format box, or over here on the Specify attributes to change icon. Either one will get me to the Change Format Settings dialog box. I want to apply a Character Style that actually doesn't exist in this document yet.

So I am going to go down to New Character Style, and I am going to create a style name called 85% Horizontal Scale. The only thing I am going to assign to this character style is that 85% value under Horizontal Scale. I'll click OK and then OK again, here. Let's click Find and it finds that. Now click Change and it applies that.

It's a very useful query. Now that I have it there, I want to be able to use this anytime I want, but I want to start from scratch. So now I am going to save this query by clicking on the Save Query icon up here, toward the top of the Find/Change dialog. When I click that, I'm given a dialog to name this query. I'm going to call it Double Dash to Custom Em Dash. I won't forget what that means.

I'll click OK, and instantly you can see that it's been added to this list of saved queries. The list in this menu is broken up into three groups, separated by this thin horizontal line that you see here. At the top of the list, above the first horizontal line, are text queries that have been saved from the Text tab of Find/Change. Below that, are GREP queries that have been saved. Below that, at the bottom of this list, are object-based queries for searching on parameters of what an object looks like.

Each query that you save is automatically saved into the right grouping. And they are listed in alphabetical order. If I start working in this document again and I clear out this field and this, and the formatting here, and I want to recall that search, I simply go up to the menu, take it from the list, and all the fields are populated. The only thing that is not saved with a query is the setting that you choose from this Search menu.

It could be Document, All Documents, Story or To End of Story and if you specified that when you created the query, it's the only thing out of all the settings that is not preserved with the query. So, remember, when you recall a saved query, you always wanted check that you've established the proper range before you run it. Not only can you save these queries for your own use later on, you can also share these queries for other users. Every query is saved as an XML file in a specific location.

Let's take a look at where it's saved on the Mac. That's where queries are stored on the Mac OS. If you're using Windows XP, this is the path where any queries you create are saved. If you're using Windows Vista and Windows 7, this is the path where all stored queries get saved. In fact, someone has sent me a saved query that I want to add to my list, and it happens to be in the Exercise Files folder. This XML file is a GREP query that cleans up the formatting of phone numbers.

It's a very useful one that someone is sharing with me. So I am going to copy this file using Command+C on the Mac, or Ctrl+C on Windows, and go to this folder where my queries are stored and hit Command+V or Ctrl+V on Windows. I can immediately go back to the Find/ Change dialog without closing InDesign, without even closing the dialog box. When I click on this menu that new query is already there. I am going to call that query up, and you can see that it's here in the field. It's a long expression that, fortunately, I don't have the write myself, because someone provided it for me.

But if I want to modify this expression, let's say I notice that this part of the expression describes three digits in a row a little bit more efficiently than this, which is any digit, any digit, any digit. So I want to modify this expression. I am going to copy this portion of it, and just clean it up to my liking. The Query menu has changed to Custom, because I've modified what was a saved query. If I save this query again, but I don't want a duplicate query, I don't want to confuse myself, I can pick that existing name and click OK and it asks if I want to replace the one that was there.

I do, so I'll click Yes. So now I have my own customized version of this, which I prefer. While I am here, I want to make this a little bit more useful. I have got all this setup from the existing query, but if I want the option to format my phone numbers with dots between the numbers instead of dashes, I can just type periods in the Change to expression, again I'm now working with a custom expression different from what was saved before to a different query. I can click Save Query again, and name this Standardized Phone Numbers-Dot and click OK.

So now I've built upon an existing query, and created a custom version of it for myself. So I have two possible options for formatting phone numbers instead of just one, and I can choose them from a list rather than ever having to create them from scratch. So every setting you define in this dialog box, with the exception of the scope that you define from the Search menu, can be saved as part of a query. Considering the potential complexity of many GREP expressions, this is a great time saver.

Show transcript

This video is part of

Image for Learning GREP with InDesign
Learning GREP with InDesign

42 video lessons · 12856 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 preferences from 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.