GREP Preview

Get a list of GREP matches in a separate document.

This script is part of the GREP collection. See the full collection here

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 vandedervan 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

Version history

12 July 2014: First posted.

Peter Kahrel Script Repository
Hosted as a community service, and with deep appreciation, by CreativePro.com


Scripts by Topic | Script Index
Basic Script Installation and Use
How to Modify or Configure These Scripts
Resources for Scripting and Publishing Automation
About This Repository


Repository Home Page


Contact Peter Kahrel


Note to users: You run scripts at your own risk: CreativePro and the author accept no liability for anything that may be caused by any of these scripts. Always take the necessary precautions. We encourage you to save backups and test scripts on copies of your documents.

Bookmark
Please login to bookmark Close

This article was last modified on August 22, 2026

Comments (0)

Leave a Reply

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

Loading comments...