Los Angeles InDesign User Group

Intermediate Level GREP Workshop

Thursday, May 16, 2019

Fire Station 59, Training Facility, 2117 Butler Ave., Los Angeles, California 90025

See the Photos

Original Event Page



By Alvin Takamori


There's always something new. In May, the Los Angeles InDesign User Group met at the Los Angeles Fire Station 59 Training Facility in West Los Angeles. It was a nice meeting room with space for tables to sit behind and multiple video screens. Who knew such a facility was available to groups such as ours?


After a welcome and brief introduction by LAIDUG Co-Manager DeShawn Burton, Chad Chelius began his presentation. Chad is an Adobe Certified Instructor, a consultant, and an author from the Philadelphia area, who came all the way to L.A. for us… Okay, actually we were fortunate that he happened to be in town and agreed to come to our meeting.


His topic for the evening was InDesign GREP, which InDesign geeks know as General Regular Expression Parser. Many people avoid it because, they think of it as complicated computer coding. However, Chad described it in a way that made it more approachable. Most people are familiar with the Find/Change command, which can search through text for a specific item and alter it. GREP also searches through text to make changes, but it searches for more than an item, it searches for patterns within the text.


As Chad provided examples of how to use GREP, it became apparent how powerful this ability to search for patterns could be. His first example was a search to find numbers at the front of a numbered list. In GREP code, a number or digit is represented by a forward slash and the letter "d". So it is written as \d. The backslash \ is an important symbol that is used often in GREP code. \d represents a single digit, so a two digit number would be represented by \d\d. What if you had a really long number? You could keep writing multiple \d\d\d… or you could add a plus symbol +. In GREP code + means one or more. So, \d+ would mean one or more digits.

Continuing with his example, Chad pointed out that numbers in a list would typically have a period and a tab space after the number. However, in GREP code a period "." by itself represents "any character". So to actually represent a period in GREP, a backslash needs to be added \. A tab space is represented by \t. Therefore, to represent a number in a list, the GREP code is written as \d+\.\t


So \d+\.\t is a pattern. Being able to describe a pattern in GREP allows you to find it and alter it. In the GREP window, there's a box where you type in the pattern to look for and in another box you type in the pattern you want to change it to. For this example, you could convert the numbers to letters, change the indent space, or change the Style. You could even do all of these at once. That is the power of using GREP.


Chad showed a few more basic GREP symbols. A straight vertical line | means "or". For example, find cent(er|re) means find the word center or centre. In GREP code \u represents an upper case letter and \l represents a lower case letter. \s represents a space and \r represents a return, and ^ represents the beginning of a paragraph.


A powerful symbol in GREP code is the question mark ? which represents something that may or may not exist. This was useful when he showed us the GREP code to search for the various ways that people write phone numbers and change them all to one consistent format. The question mark is used to search for parenthesis, periods, or hyphens that may or may not exist. The item that may or may not be there is followed by the question mark. For example, \(? means an opening parenthesis that may or may not exist.


Brackets enclosing a series of code is one way to create a set of items and apply a GREP command to all the items. In the telephone example, [-.]? the brackets enclose a hyphen and a period. The following question mark? is applied to both items indicating a hypen or period which may or may not exist. So a telephone number in GREP would be symbolized as\(?(\d\d\d\)?[-.]?(\d\d\d)[-.]?(\d\d\d\d). To break it down, it means an opening parenthesis that may or may not exist \(? followed by a group of three digits (\d\d\d) followed by a closing parenthesis that may or may not exist \)? followed by a hyphen or period that may or may not exist [-.]? followed by a group of three digits (\d\d\d) followed by a hyphen or period that may or may not exist [-.]? followed by a group of four digits (\d\d\d\d)


In the telephone number example, parenthesis without a forward slash are used to form groups. In the GREP window, after creating a group in the search box you can represent the group in the "change to" box with a dollar sign and number. Going back to the telphone example, instead of rewriting (\d\d\d) in the change box you can represent the group by writing $1 So, to convert the various ways that people write phone numbers to a format where the groups of numbers are separated only by periods, you would take the code \(?(\d\d\d\)?[-.]?(\d\d\d)[-.]?(\d\d\d\d) and enter it in the search  box but in the change to box, all you would have to write is $1.$2.$3


Chad provided another example, using GREP to take a list of names and changing it so that the last name is switched to the front. The pattern for a name is an upper case letter followed by one or more lower case letters. In GREP code that is written as (\u\l+). So to make the desired change, a search for names represented as (\u\l+)\s(\u\l+) would be changed to $2,$1 which represents last name followed by a comma, then first name.


Another interesting feature of GREP is the ability to search for a pattern, then look at what is in front of, or behind that pattern. You could then change those things in front or behind, without altering the pattern that you originally searched for. As an example, Chad created a search for text inside of parenthesis. In GREP code (?<=) means to look for something behind. The pattern you are searching for would be added inside the parenthesis after the equal sign. For Chad's example, he was looking for something after an opening parenthesis \( This would be represented by the following code (?<=\() A period . represents any character and a plus sign + would indicate one or more characters. (?=) means to look for something ahead or in front of. Once again the pattern you want to search for is added after the equal sign. For our example it is something in front of a closing parenthesis \), represented as (?=\)) So to search for any text inside of parenthesis, the code would be (?<=\().+(?=\)) You could then proceed to make whatever changes you want to the text inside of any parenthesis without altering the parenthesis themselves. Again, you are looking at what is after the opening parenthesis and in front of a closing parenthesis.


Chad also explained how GREP can be used to automate changing text using Character Styles and Paragraph Styles. He demonstrated this with an example searching for specific text to highlight. He also demonstrated how to evenly space text inside a row of boxes and how to highlight every other row of a list.

A major advantage of using GREP instead of Find/Change is that even if the text continues to be edited, the GREP commands will automatically be applied to any new text. On the other hand, a new Find/Change would have to be applied any time there is a change to the text.


The use of GREP is far easier to understand when you see the effect demonstrated, then it is for me to try to describe in words. There is a trial and error process in seeing what effect a GREP command actually has. However, even if you are uncomfortable with coding there's already a list of common GREP patterns pre-loaded in InDesign. GREP's ability to make significant changes through huge volumes of text, and to do so automatically, is potentially a huge time-saver that makes it worth exploring.


To learn more Chad recommended "Treasures of GREP" on Facebook or you can twitter him @chadchelius.




Special Raffle Prize


Beats by Dr. Dre Studio Over-Ear Black Headphones—Alan Gilbertson



Farthest Attendee Prize Winner


Mighty Deals—Alejandro Rubalcava



Raffle Prize Winners


Adobe Creative Cloud. 12 month subscription—Susan Reuben

LinkedIn Premium. 12 month subscription—Candice Ota, Chip Reuben

GoProof from Oppolis Software. 3 month subscription for 2 users—Alejandro Rubalcava

MT from Markzware. 12 month subscription—Susan Reuben

Expo Creative Asset Manager for Mac from Insider Software—Wayne DeSelle

Suitcase Fusion 8 from Extensis. 12 month subscription—Alan Gilbertson

Font Agent Pro 8 from Insider Software—Susan Reuben

DTP Tools Cloud for InDesign. 6 month subscription—William Baughman

Multi-Find/Change 3.0 from Automatication—Michael Powe

Adobe Stock. 15 image licenses—Wayne DeSelle

InDesign Magazine. 6 month subscription—Dallas Mathers

LA Web Professionals Group meeting tickets—Deena Bowman, Rocie Carrillo, Chip Reuben, Susan Reuben



Copyright © 2019 Los Angeles InDesign User Group. All rights reserved.