Targeting Character Ranges with GREP

Learn how to find a sequential range of letters or numbers using GREP in InDesign

You can use [brackets] in a GREP expression to find a sequential range of letters or numbers in InDesign.

Finding letters

If you want to find a series of letters, e.g., letters a to f, you can use this expression: [a-f]. This will start counting from the letter a and follow the alphabet until it gets to f. Notice this will all be in lowercase characters. If you want to find these letters in both upper- and lowercase, you can use this expression instead: [a-fA-F]. So here you’re running two ranges at the same time, using the alphabet to set the range.

Finding numbers

The same works with numbers, which GREP will count from 0 to 9. Just remember that GREP doesn’t understand multi-digit numbers. For example, if you want to find everything from 36 to 52, you can’t just type [36-52]; you have to consider these numbers as compound numbers. You’d use the following expression instead: 3[6-9]|4[0-9]|5[0-2]

Let’s break this apart to understand it better. 3[6-9] will find a digit that starts with a 3 and is then followed by a 6, 7, 8, or 9. This will find numbers 36, 37, 38, 39.

The | symbol officially means “or” but actually means “and/or,” because it will connect your GREP chunks and find everything together. 4[0-9] will find the complete forties series, up to 49. And 5[0-2] will find 50, 51, and 52.

Adobe Bridge tip: When you’re using the Batch Rename command in Adobe Bridge to rename entire folders or selections of files, you can click the Use Regular Expression box, which will allow you to use GREP to target a range of specific filenames. So next time you empty your camera and have a series of images named like this…

img-346.jpg

img-347.jpg

img-348.jpg

…you now know how to target a specific series of images to change their names.

Bookmark
Please login to bookmark Close

This article was last modified on November 17, 2023

Comments (1)

Leave a Reply

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

  1. Dhafir Photo

    You must using the capturing group (…) and word boundaries b in order to limit the search to the exact range.
    b(3[6-9]|4[0-9]|5[0-2])b Matches the range 36-52
    But 3[6-9]|4[0-9]|5[0-2] matches every 36, 37, 38, …to 52, in any scalar sequence, such as: 136-152, and 360-520