Menu

Need training at your office? Request a quote for custom training.

Home / Adobe InDesign / Adobe InDesign: GREP to Replace Hyphens with En Dashes

Adobe InDesign: GREP to Replace Hyphens with En Dashes

By Barb Binder, Adobe Certified Instructor on InDesign
Updated on Sep 30, 2016

What in the world is General Regular Expression Print (GREP)? Wikipedia defines it as “… a command line utility that was originally written for use with the Unix operating system. Given a list of files or standard input to read, GREP searches for lines of text that match one or many regular expressions, and outputs only the matching lines.”

What? Well, in plainer language, by searching for patterns rather than specific characters, GREP is a way to a take InDesign’s Find/Change to a whole new level.

As my good friend and grammar teacher extraordinaire Jennie Ruby once told me, use an en dash between ranges of numbers when you would say the words “to” or “through”, as in “see pages 14-20 in the reference guide.” So what do you do when your writers use hyphens between digits instead of en dashes? You certainly can’t just search for all hyphens and replace with en dashes (you’ll mess up all the hyphenated words).

Find/Change Text comes so close. You can use the special character list to search for any digit, an en dash and any digit, but there’s no way to replace the digits. In my pre-GREP life, my best bet was to run 10 individual searches: Search for 1-, replace with 1–; search for 2-, replace with 2–; etc.

Enter GREP. You can enter in a fairly simple GREP query that will find all Arabic numerals with a single hyphen and change those hyphens to en dashes. Try this one next time you have to update your hypens to en dashes:

  1. Choose Edit>Find/Change
  2. Click the GREP tab
  3. Add the following strings:
    Find What: (?x)\b(d+)-(d+)b
    Change to: $1~=$2
    GREP 2
  4. Use the Find, Change, Find & Change and Change All buttons to update your documents.
  5. And don’t forget to save the Query so that you can use it again and again!

Try it and tell me that isn’t awesome! I just wish Adobe would add GREP support to FrameMaker, too.

By the way, the best resource I’ve found so far to teach myselft GREP is “GREP in InDesign CS3/CS4” by Peter Kahrel. You can purchase his e-book for just $10 here. It offers clear explanations and numerous examples of common searches.

Leave a Comment

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

4 thoughts on “Adobe InDesign: GREP to Replace Hyphens with En Dashes

  1. In Step 3, you wrote:
    Find What: (?x)b(d+)-(d+)b
    But I think what you meant was (as it shows in your screen shot)
    (?x) b (d+)-(d+) b