is now part of CreativePro.com!

Selecting Horizontal and Vertical Spaces with GREP

8

by Erica Gamet

If you use GREP in InDesign, you either know the name Peter Kahrel or you should. He literally wrote the book on using GREP specifically in InDesign. I had the pleasure of meeting him in person at this year’s PePcon (in my GREP session, so no pressure there). He let me in on a little addition to InDesign’s sub-set of GREP expressions that goes back to CS6. The wildcards \v and \h represent vertical and horizontal white space, respectively.

The \v wildcard will find both hard and soft returns, so it can be used in place of the [\r\n] expression. However, the \h expression has even more promise in that it will find all white space except for the return character \r. That will make looking for two or more spaces even easier.

The built-in GREP expression for “multiple space to single space” looks for [~m~>~f~|~S~s~<~/~.~3~4~%]{2,}, which looks for each specific type of white space when there are two or more together. We’ve always been able to simplify it as \s{2,}, but unlike the previous expression, that will also find—and change—multiple returns.

Using the \h command, that expression can be written more simply as \h{2,} which will find everything from the first expression, as well as multiple tabs in a row, but not the multiple return characters.

ids_20140714-horizgrep3

For those who use GREP for text clean-up a lot, this could be a huge timesaver. If you’re not using at least the built-in GREP expressions to automate with InDesign, what are you waiting for?

  • I love these GREP hidden gems…

  • Aaron Gray says:

    Great post, Erica! I use the Multi-Find/Change extension for a lot of text clean-up. I need to wrap my head around this and see if I might not be able to combine multiple steps into one. Thanks!

  • Eugene Tyson says:

    Brilliant!

  • Anas Albounni says:

    thats REALLY helpful, many thanks for sharing

  • Gary Stolz says:

    Thank you! My clients get irritated when I ask them to clean up their copy. They just don’t want to change old habits.

  • Bart Van de Wiele says:

    What a great tip!

  • Masood Ahmad says:

    Thanks, nice tip !
    :Peter, are there any more hidden gems, please share if yes.

  • Obi-wan Kenobi says:

    … Just to continue this discussion, how to quickly find the “bad” spaces between words as, e.g., an “~S” space between “Grep” and “is” in:
    “Grep is Great! …”

    (^/) ;-)

  • >