Skip to Content
GREP in InDesign CS3
book

GREP in InDesign CS3

by Peter Kahrel
October 2007
Intermediate to advanced
47 pages
1h 12m
English
O'Reilly Media, Inc.
Content preview from GREP in InDesign CS3

Chaining Expressions

We've seen that it is often preferable, and sometimes even necessary, to use more than one expression to achieve something. But unfortunately it is not possible in GREP's interface to chain two or more expressions, so you may find yourself running saved queries in succession. However, to get around this, we can create a script with all related expressions and run it from the scripts panel. It may look a bit intimidating at first, but it's in fact not too complicated once you get the hang of it. Besides, the scripts shown here don't involve any real programming; they're essentially a series of statements. In that respect they're more like actions.

The scripts illustrated here are in JavaScript, which can be used both on Macs and Windows. The first script combines four expressions that we illustrated earlier, namely the two that replace hyphens with en dashes in page ranges, and the two that drop digits from ranges. In the first script, below, the first two lines clear the tab of any settings, after which we include a line to include footnotes in the replacements. Then there are four sets of three lines, and once you work your way past JavaScript's verbosity you can easily see the expressions that we've been dealing with in this Short Cut. Note that the backslash must be escaped, which is why you see the double backslashes. You could easily use this script as a template for other expressions:

// Reset the GREP tab app.findGrepPreferences = null; app.changeGrepPreferences ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

GREP in InDesign

GREP in InDesign

Peter Kahrel
Adobe InDesign CS5 On Demand

Adobe InDesign CS5 On Demand

Steve Johnson - Perspection, Inc.

Publisher Resources

ISBN: 9780596517069Errata