GREP preview

The GREP editor (see here) highlights matches in a text. This is useful because you can see at once what your GREP expression matches. But to see all matches you'll have to scroll through the text, and there will often be a lot of repetition. Highlighting, then, is not always the best preview.

Therefore, if you're working on a long text and plan a GREP replacement, it would be useful to see what your GREP expression matches -- in a list with all duplicates removed. The script described on this page collects all your matches and, optionally, previews replacements as well.

Previewing matches

To use the script, first write a GREP expression, e.g. the following ('find the word position with any preceding and following letters and digits'):

GREP preview InDesign

and click Find Next to make sure it matches something. You must press that button anyway: if you don't click Find Next, the script can't see the GREP expression.

Now run the script; it displays this small window:

GREP preview InDesign

Ignore the 'Show replacement results' checkbox for now, just click OK. The script collects all matches, and displays them all in a new document, sorted and with duplicates removed:

GREP preview InDesign

Previewing replacements

Apart from previewing matches, you can preview replacements too. The replacements aren't made in your text, they're shown in a new document. Take the following example:

GREP preview InDesign

This expression matches names in the form first name, any defined prefixes (here, just van, de, der, van de, and van der), last name. The change field replaces these names to the form last name, comma, first name and any prefixes.

To get the replacement preview to work, you must apply the find and change fields, so to speak, so that the script can see both. To do that, (1) click Find Next; (2) when you found something, click Change; (3) undo that change by pressing Ctrl+Z.

Now run the script and tick the checkbox:

GREP preview change InDesign

Press OK. The script places all the found items in a new document, and shows the replacement result after each item:

GREP InDesign preview


Useful script?

Consider making a donation. To make a donation, please press the button below. This is Paypal's payment system; you don't need a Paypal account to use it: you can use several types/brands of credit and debit card.

Peter Kahrel's paypal account


Version history

12 July 2014: First posted.


Show script (right click, Save Link/Target As to download)

Back to GREP page

Back to main script page

Installing and running scripts

Questions, comments? Get in touch