Thanks for coming to, the world's #1 resource for all things InDesign!

Selecting Horizontal and Vertical Spaces With GREP

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.


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?

Guest Author

Guest Author

Guest Author

Latest posts by Guest Author (see all)

Related Articles

8 Comments on “Selecting Horizontal and Vertical Spaces With GREP

  1. 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!

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

  3. … 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! …”

    (^/) ;-)

Leave a Reply

Your email address will not be published. Required fields are marked *