GREP Change Case (Pre-2024)

Using InDesign's Find/Change dialog, you can't change the case of what your GREP matches. Thus, you can't change acronyms in upper case to lower case and apply some style to...

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

This script is obsolete and largely available for historical purposes. See the full collection of scripts for older InDesign versions here.ย 

InDesign 2024 introduced case folding, so the script isn’t needed in this and subsequent versions. I’ll leave this script here for historical reasons.

InDesign’s GREP is powerful, but one feature it lacks is case conversion: you can’t change the case of what your GREP expression matches. But this can be remedied by a script that acts as a kind of extension to the Find/Change dialog.

The script is an extension of the Find/Change dialog in that it must work in conjunction with it. You first devise a GREP expression that matches the text that you want to change, then you run the script, which takes over from the Find/Change dialog from there on. I’ll illustrate it with some examples.

What prompted the script was this scenario. The document I was processing was a bibliography with dozens and dozens of paragraphs with titles of books and articles in which the subtitle always started with a capital, as in Repetition: A boring affair. In this title, A should be a; similarly, if a subtitle begins with The, it should be lower-cased to the, and there were a small handful of other function words that should be lower-cased when they were the first word of a subtitle.

Because this can’t be generalised you have to look for a capital preceded by a colon and a space, then convert that letter to lower case. Even if you’ve defined “convert to lower case” to a keyboard shortcut, this is tedious stuff. The script makes things a lot easier. In the example sketched here, the script is used as follows.

1. Define a GREP expression and make sure that it matches correctly. I needed to find capitals preceded by a colon and a space, which is easy: (?<=:\s)\u. The lookbehind isn’t really necessary because naturally when you convert the case of punctuation and white space nothing happens, but I try to make a habit of matching only what is needed.

2. After establishing that the GREP expression matches what you want, run the script. It shows this panel:

grep change case

In the top panel, A > a indicates that we’re changing upper case to lower case. If you want to change lower to upper case, simply click the second radio button. You can switch between the modes as you go along.

To apply smallcaps to letters converted to lower case, check the Apply SC box.

The FindChangeChange all, and Change/find buttons function exactly as they do in the Find/Change dialog; in that sense the script is an extension of that dialog.

Since the script uses InDesign’s Find/Change, it respects all settings in the dialog for formatting and search area (include or ignore footnotes, master pages, etc.). The only exception is that what you select at Search: in the dialog (Document, Selection, etc.) is ignored: if you press the script’s Change all button, the whole document is processed.

Acronyms

Another example of what the script can be used for is to convert acronyms in upper case to lower case and apply a style to them, either local small caps or a character style. This is just a slight variation of the example given earlier:

1. Define a GREP: \u\u+, and enter the small caps style in the Change Format: pane of the Find/Change dialog.

2. Run the script, using the buttons to change or ignore matches.


Version history

17 Jan. 2024: The script showed strange behaviour when found texts were in different stories. Fixed.

28 Jan. 2015: The script crashed in overset text. Fixed.

13 Jan. 2015: Fixed an interface problem caused by CC 2014.

16 May 2012: Rewritten. Fixed memory issues.

Sept. 2010: 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...