is now part of CreativePro.com!

InDesign GREP Essentials: Ready-to-use Expressions

6

This article is part of in a series of posts on using GREP in InDesign for beginners.

Learning GREP isn’t easy. Fortunately, InDesign comes with a few ready-to-use expressions already written for you. The two I use the most are especially handy for cleaning up Word files riddled extraneous white space (extra spaces after punctuation and extra returns).

Multiple Return to Single Return

In the Find/Change dialog box, go to the Query pull-down menu. The middle section contains GREP searches. The “Multiple Return to Single Return” query looks for two or more consecutive returns and replaces that pattern with a single return. The expression is written as ~b~b+. The first ~b (for break character) finds the hard return that denotes the end of a paragraph: we need that one. The second ~b means there is at least a second hard return and that one has to go. If we knew there were always only the two, we could stop there. Problem is, people that throw in one extra return have no regard for common decency, so you can’t know that they didn’t throw in another return. Or five. The plus sign in the expression, remember, indicates one or more times, which covers an infinite number of returns. It then changes the found text to a single return.

The built-in expression to find at least two of any kind of space

The built-in expression to find at least two of any kind of space

Multiple Space to Single Space

The “Multiple Space to Single Space” query is truly a thing of beauty. As the name suggests, you can clean up all those pesky extra spaces that people still insist on putting in after punctuation. If you’re looking for [space][space] and replacing it with [space], get ready for a huge upgrade. The [space][space] way does no good when the person who made the file put in three spaces in a row, or thought it would be clever to use two en spaces and a thin space, for some unknown reason. The ready-to-use expression, on the other hand, uses a character class (the text within square brackets) to say, “Find any one of these characters.” It doesn’t care what order they’re in or if there’s a combination of them. The {2,} you should recall indicates 2 or more times (see: InDesign GREP Essentials: Quantity). The query then returns everything that fits that pattern with a single, simple word space, \s.

Erica Gamet has been involved in the graphics industry for over 35 years. She is a speaker, writer, trainer, and content creator focusing on Adobe InDesign, Apple Keynote, and varied production topics. She is a regular presenter at CreativePro Week, regular contributor to CreativePro Magazine, and has spoken at Canada’s ebookcraft, Adobe MAX, and Making Design in Oslo, Norway. Find Erica online at the CreativePro YouTube channel, CreativeLive.com and through her own YouTube channel. When she isn’t at her computer she’s probably daydreaming about travel or living in a Nordic noir landscape.

Website
LinkedIn
Instagram
  • The built in “Multiple Space to Single Space” in InDesign can kill you XML-Tags, Notes and Index-Markers.

    Better use this GREP:

    \h(?=\h)

    \h is available since CS6 and stands for all Space-Chars (including \t) and (?=\h) is a positive Lookahead.

    • Gregor,

      I’m looking at the stock Mulitple Space to Single Space search, and my GREP skills aren’t sufficient to tell me where in that search string your replacement characters should be inserted.

      Could you post how that revised search string should look? Thanks!

  • There’s another handy text cleanup routine. That’s number ranges such as 37-43, where a hyphen needs to be changed to an n-dash (37–43) for publication. There are lots of such hyphens in some manuscripts, expecially those with endnotes, so done manually by just searching for a hyphen and making a manual change (or not) can be sheer misery.

    One solution is to search for a number followed by a hyphen followed by a number. That’ll find you all the range of numbers uses for the n-dash, reducing your work load a bit. It is not perfect though. You’ll still have to make those changes manually as each search result comes up, since html addresses often have hyphens between numbers that should not be changed.

    And alas, doing hundreds of such changes often so numbs the mind that you’re likely to make a mistake that you only discover when ID has jumped to the next hyphen. That’s why I pleaded with the ID group, when it was in Seattle, to add a reverse search which, bless their hearts, they did with ID-2015. That lets you search back to that mistake and fix it. Three cheers for ID-Seattle.
    —–
    Another use for searches in general is to standardize terms. In a book about tree landscaping, is it crepe myrtle, crepe-myrtle or crepemyrtle? Whatever the decision, searching for the non-standard spellings will ensure conformity.

    That brings up another issue for Adobe or a third-party scripter. All ID’s searches (not just GREP) could use a double look-for and a double or more replacement ability. In the case of those hyphens, it’s be helpful to search for all hyphens and have three choices rather than two:

    1. No change. The hyphen is correct.

    2. Replace with n-dash.

    3. Replace with m-dash.
    ——
    And that brings up the final and most dangerous problem. Look at the Find/Change panel in ID-2015. (I’ve not downloaded ID-2017, but I’ve seen no mention of a change.) Here is how the buttons are arranged.

    Find Next
    Change
    Change All
    Change/Find

    Now imagine a control panel in a nuclear missile silo that has this set of button.

    Turn on Silo Lights
    Test System
    Initial Global Nuclear War
    Turn On Silo Lights/Test System

    Do you see what’s wrong? Change All is the nuclear option. Yes, there is Undo, but do you really trust it to get you back to exactly what was before that inadvertent Change All? I don’t.

    The problem is that the buttons are arranged to look pretty. They stack top-to-bottom from the shortest to the longest. They’re not arranged functionally. In most searches, users are either clicking on Find Next to do nothing and move onto the next search result or Change/Find to make the change and move to the next. That’s moving from the top button to the bottom one hundreds of times. Just miss Find Next and you’ve made a change you did not want. Miss Change/Find and you click on Change All, which you emphatically did not want.

    The fix would be an easy one. Simply move that dastardly Change All to the bottom and put some safe space between it and the other buttons.
    —–
    One additional suggestion. You might want to make these changes early in your layout process. The more passes over the text that you make after these global changes, the more likely your are to catch inadvertent errors of omission or commission. And changes such as ridding a text of double spaces or returns can impact page breaks, so they are best done early.

    –Mike Perry, Inklng Books

  • Morgan Besson says:

    I see that “Multiple Return to Single Return” replaces ~b~b+ with \r. Would replace \r\r+ with \r also work? What is the difference between ~b and \r?
    Thanks
    -Morgan

    • Erica Gamet says:

      The differences are slight, but could make a difference depending on your particular document. ~b is the hard return character, while \r includes other breaks such as column break. Which is confusing, because I’m always sure it’s the other way around.

  • >
    Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo