Peel Me A GREP


I am not a scripter, nor do I play one on TV. I know my share of HTML, CSS, and XML, but really I’m just an old school publishing geek who never tires of learning the next trick or tool. My hands are all GUI from years of keyboard shortcuts.

I know scripting is in my future. It’s just too powerful, too useful, too cool to put off much longer. And I am totally jealous of the power of scripters. It’s not like I haven’t tried. I’ve attended AppleScript and JavaScript seminars, but they didn’t stick. Hell, I have driven around an 800-page JavaScript book on the passenger seat of my car all summer, in hopes that it would start talking to me during my commute. No dice. So as a gentle, evolutionary step toward scripting, I’ve been working to learn GREP within InDesign

GREP was added to InDesign with CS3 as a more powerful means of finding and replacing text. While it sounds like something you should be inoculated against (“The nurse gave Johnny his Dip/Tet, his Grep, and a lollipop.”) it really stands for General Regular Expression Print. Forget the General and the Print part, the heart of it are these things called Regular Expressions, little secret codes that function in a Find/Change operation. And they make GREP searches a jillion times more powerful than a plain Text search.

Text search in InDesign only gives you four wildcards: Any Digit, Any Letter, Any Character, and Any Whitespace. GREP has those plus many more wildcards. It also lets you look for locations, like the beginning and endings of words and paragraphs. So you can say “find every word (of any length) starting with a capital letter”.

It lets you specify repeat values, so you can say things like, “find every number of three or more digits”. Or, even fancier, “find every hyphen in between numbers of three or more digits”.

And you can add logic, to say find “Mike” or “mike,”, or find every word ending in “ike,” except “Mike.”

And it lets you take any part of a found expression and leave it alone. So you can find phone numbers, add parens around the area codes, and leave the numbers themselves unchanged.

Combine this text-finding ability with Find Format settings, and I think it’s fair to say you can now Find/Change anything you can think of in an InDesign document. Providing you’re thinking of text, of course.

The only “problem” with GREP is, it’s more digital trivia to learn. Your brain’s already addled with passwords, keyboard shortcuts, file formats, and the names of all the actors on Barney Miller. For the love of Abe Vigoda, how are you going to learn GREP codes?

You can just start playing, but that can be frustrating to say the least, because like all coding adventures, you don’t get much feedback when you’re doing it wrong. Nothing happens, or the wrong thing happens and you have no idea how to fix it. I bought the O’Reilly Safari book on GREP in InDesign CS3, which very good, well worth the $10. But there’s something even better, and it comes from New Zealand.

For learning GREP, there’s a great, free online tool called The Lightning Brain GREPGrokker. It’s offered up by Rorohiko Ltd. who also have a bunch of free and commercial plug-ins for InDesign (make your own Sudoku! Sweet!). The GREP Grokker is an interactive tool for learning GREP. You can follow the step-by-step instructions and see how typing in certain codes selects text. Or you can type/paste in your own text and search on that. It is just so cool to see how the selection changes as you change your codes. It’s very “oooh”, “ahh”. Check it out. And check out Rorohiko’s other plug-ins. There’s some fun free stuff in there. Like if you used to love Quark’s Jabberwocky, they have a version of it for InDesign.

Advertisements

3 Responses

  1. I had only heard “general regular expression parser” (for GREP) before. Interesting that it appears to also mean “print”. This is terrific info. We also have more on grep at indesignsecrets.com/grep.

  2. Yeah, the “print” thing sounds weird. I got it from the O’Reilly Short Cuts thing, and double-checked it on Wikipedia. I think in this case “print” just means “output”, where output is the found text ($0, $1, etc in GREPspeak).

    It’s all GREP to me. ; )

  3. You know what’s neat is using GREP in OSX’s Terminal app. There you can use GREP (carefully of course) that not only *finds* things … anywhere on your hard drive (including inside text files) … but that can also *do* things to them like change names, create files, delete files, (folders too), and my favorite, create a text file of what it found, or put it in the clipboard, or send it to print. (Which is why I thought of that, from your “P=Print” thing.)

    It uses slightly different codes, and then there’s all those extra ones that I wish I could use in ID. I mean it would be so cool if there was a Print or Export button in the Find/Change GREP area, so it could print what it found.

    Here’s an article from a few years ago with some examples, they still work as described.
    http://www.macworld.com/article/41504/2004/12/jangeekfactor.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: