Los Angeles InDesign User Group

Getting a Grip on InDesign’s GREP

Thursday, January 21, 2016

The Art Institute of California, 2950 31st St., Santa Monica, CA 90405

See the Photos

Original Event Page

 

 

By Alvin Takamori

 

Kicking off 2016 the Los Angeles InDesign User Group met on January 21st at The Art Institute of California in Santa Monica.  A nice crowd filled the classroom and they were in for a real treat. Donuts! We also had a really special guest speaker in Erica Gamet. Proving that if enough people attend and buy some raffle tickets, we can have nicer snacks and bring great presenters from out of state.

 

Erica is an expert on Adobe InDesign, Illustrator, and Apple Keynote. She conducts training for individuals and corporations and regularly contributes to InDesign Magazine and CreativePro.com.

 

On this night Erica shared her knowledge of GREP expressions for InDesign. GREP is a command line utility originally written for the UNIX operating system. It’s function was to Globally search for matches to a Regular Expression and Print. In other words, it could look through a lot of text for something that matches a recurring pattern.

 

For many people, the initial response to GREP is to think computer programming and run away. Erica’s goal was to break through that fear and bring some understanding as to how useful GREP can be.

 

In InDesign one place to access GREP is to go to the Edit menu and select Find/Change. The key to GREP is to recognize frequent patterns in the text. Look for the patterns you want to change and find the GREP characters to describe the patterns. That description goes into the Find box. Then create the GREP expression to describe how you want the text to look and that goes into the Change box. Admittedly, this can be a trial and error process. When you hit the Find Next button, you can jump through text, from one section to the next section that the change is applied. This way you can see if the correct change is taking place.

 

There are some GREP characters that are basically computer commands, which are helpful to learn. But before you throw your hands up and scream, “That’s too complicated!” go to ericagamet.com and look under the Tips and Tricks menu to find her GREP Quick Reference Chart. There are a few basic characters that you can start with to get a sense of how they work.

 

The backslash \ is a key symbol. It appears in front of many letters and symbols to convert them into meaningful GREP characters. For instance \d represents “any digit”. In other words, it’s any number. \l represents any lowercase letter and \u is any uppercase letter. \w is any word. \s is a space between words and \t is a tab. If you actually needed a backslash, in GREP that would be represented by adding another backslash \\.

 

On her website, Erica breaks down some of these GREP symbols into categories. There are characters that represent objects like a number, a letter, a word, or a space, etc. Then there are characters that represent locations like the beginning or end of a word, paragraph, or story. Other symbols indicate how many times an item appears in a sequence. Another group consists of symbols like parentheses to group expressions and brackets to create a set of characters.

 

Erica Gamet proceeded to run through a series of examples demonstrating how GREP could be used. She showed how GREP expressions could be used to automate the conversion of the last two digits (representing cents) of any monetary amount and convert them into superscript. You could convert type framed by quotation marks into italics and remove the quotes. That’s a notable aspect of using GREP. It gives you the ability not only to alter type, but to remove things.

 

GREP could also be used to convert multiple returns into a single return and multiple spaces into a single space. One way to express multiples in GREP language is to add a plus + symbol. For instance, ~b~b+ means two line breaks or more. A question mark indicates zero (the pattern doesn’t exist) or it occurs one time. Combine the two symbols +? to create a GREP meaning zero or more times with the shortest match. Brackets also convey repetition. The expression {2} means something repeats twice. Adding a comma {2} changes the meaning to repeats two or more times. Add another number to place a limit. For instance {2,4} means something repeats 2,3, or 4 times.

 

Square brackets are also very useful in GREP language for creating sets. For example, [1-4] means look for numbers 1 through 4. But if you move the hyphen and create this [-14]; it means look for a hyphen, or a one, or a four. If you create this set [aeiou], it means look for all the vowels.

 

A pike symbol, which is a straight vertical line, means ”either or”. For instance, grey|gray means find grey or gray. The same idea could also be written as gr(e|a)y. Find an “e” or an “a” with “gr” in front and a “y” after it.

 

In another example, Erica demonstrated how to make changes to a list of presidential names. Using parentheses, she created groups of GREP expressions representing the first name, the last name and if it exists, the middle name or initial. Then in the Change box she could rearrange it to put the last name first. In GREP language, it’s written as $3 $1 $2. The dollar symbol in front of numbers indicates a grouping, first group, second group, etc.

 

Next there was a demonstration of how to write a GREP expression that searches for the various ways that people write telephone numbers and converts them into a single format.

 

Another interesting aspect of GREP is the ability to look for patterns in the text, but instead of changing those patterns, using them as indicators to find neighboring text to change. Referred to as Positive or Negative Look Ahead or Look Behind. A Positive expression means if you find this pattern, change the text in front of it or behind it. Negative means, if you do not find the pattern then change the text. For instance, going back to the first example, if you were changing the last two digits representing cents of a monetary amount to superscript, you could use a Positive Look Behind. It would be written in GREP characters as (?<=)  For this example, you want to look for the two digits behind a period. So the GREP expression would be written as (?<=\.)\d\d

 

Erica went on to demonstrate how GREP expressions could be used to create bulleted lists, footnotes, automate the application of styles, and even apply a graphic.

 

Admittedly, learning the vocabulary of GREP can be a bit intimidating. However, there are information sources like Erica Gamet’s website and someone she recommended, Peter Kahrel, along with Adobe’s site. They have lists of GREP symbols and expressions. Even if you don’t know the meaning of the specific characters, you can still go to these websites and others and just look for what you want to do. Want to change a list of phone numbers into one format? Just lookup that process and copy the expressions into the Find and Change boxes.

 

There seems to be a lot of willingness to share GREP expressions. In fact, although I heard this second hand and don’t know the details, Erica gave an example of applying a stlye of bold using a Positive Look Ahead with a colon as the marker. She learned this expression from someone who happened to be in attendance at our meeting. I think it was Luis Madrigal. If I have this wrong, I apologize, but it provides an axample showing that you don’t have to reinvent the wheel. A lot of smart people have already created many useful GREP expressions that they’re willing to share.

 

As you can see, Erica Gamet knows a lot about GREP and in a few hours she shared a lot of information. She also did this in such an engaging way that the people who attended filled the opinion forms with words like, “great,” “excellent,” “awesome,” “informative,” “knowledgeable,” “terrific,” etc. If you were there, you know what they meant. If you were not there, you missed out.

 

 

Farthest Attendee Prize Winner

 

InDesign Magazine. 6 month subscription—Douglas Wade

 

 

Raffle Prize Winners

 

eDocker CREATE! 6 month subscription—Barbara Fier

Stock Layouts. Full access to Stock Layout template library. 3 month subscription—Jeffrey Schimsky

Markzware. Any single product. 12 month subscription—Douglas Wade

Expo Creative Asset Manager for Mac from Insider Software—Barbara Fier

Font Agent Pro 6 from Insider Software—Barbara Fier

InMotion Hosting. Web hosting and free domain—Barbara Fier

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

Fotolia. 3 month subscription. 5 images per month—Barbara Fier

TypeDNA. Font management software—Douglas Wade

Digital-Tutors. 1 month subscription—Barbara Fier, Laurie Miller

LA Web Professionals Group meeting tickets—Chip Reuben, Susy Reuben, Douglas Wade, Bing Wong

 

Note: Barbara Fier bought a lot of raffle tickets.

 

 

 

 

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