InDesign GREP Essentials: How to Add, Delete, and Re-Arrange Text
This article is part of a series of posts on using GREP in InDesign for beginners
One of the biggest advantages to using GREP with Find/Change in InDesign is the ability to manipulate the text you’ve found. For instance, you could find everything that fit the pattern of a price: \$\d+,*\d+\.\d{2} and then in the Change to field you could tell InDesign to put “Price: ” in front of that found text.
To do that, put the expression above in the Find what field. In the Change to field, enter Price: . Next, you have to tell InDesign to take the text it found with the expression and plop it right after the text you want to add. You can find what you need in the secret menu hiding under the @, under the Found sub-menu. Choose Found Text, or simply enter $0 (dollar sign zero). Now when you run the query, it’ll find everything that fits your price pattern and add Price: before it.
Using Subexpressions
By segmenting the expression into subexpressions you can manipulate those groups individually. For example, in a phone number, you may want to find ten digits, then offset each portion of the phone number by dots or dashes. Use subexpressions to break that long string of numbers into its three parts (area code, prefix, and line number). In InDesign, subexpressions are indicated by wrapping each up in a pair of parenthesis. So, to divide a 10-digit phone number, you would write the expression like this: (\d{3})(\d{3})(\d{4}). Each subexpression gets assigned a number, and in our example we have three, numbered left to right. You can have up to nine subexpressions in one GREP expression.
Let’s use those subexpressions to add dots between each segment of the phone number. Use the expression above to find any string of 10-digits in the Find what field. In the Change to field, use the secret menu to enter: Found (group) 1, then enter a dot (period), then Found 2, followed by a dot, followed by Found 3. The final expression would look like this: $1.$2.$3.
Note that in the Change to field, a period is stated as simply a period. When looking for a period in the Find field, you have to precede it with a backslash because a period is a wildcard for “any character”.
Deleting Content with GREP
If you wanted to drop off the area code in a phone number (perhaps they’re all the same) simply don’t “return” the group of found text that represents the area code (group 1 in our example). The Change to field would look like this: $2.$3.
Rearranging Content with GREP
You can also return groups in another order, which comes in handy for doing first name/last name reversals, for example. To do that, just reverse the order of the found items in the Change to field: $2$1
This article was last modified on July 25, 2019
This article was first published on February 13, 2017


