Thanks for coming to, the world's #1 resource for all things InDesign!

Adventures in GREPland

There’s been no shortage of enthusiasm for the power and coolness of GREP in InDesign. But for someone coming from a blissfully code-free upbringing, it can be a hard thing to get a handle on. One of the hurdles for anyone learning GREP is that when you do it wrong, there’s not much feedback about what you did wrong. Often there’s no partial success. The expression you write either works or it doesn’t. And when it doesn’t, the silence coming from your machine is deafening. In the past, I’ve recommended that folks check out the GREP tutor at Rorohiko, since it gives you instant feedback as you type. But today it hit me that there’s a way to get some of that same kind of instant feedback right in InDesign by using GREP styles.

To illustrate, take some text and reduce it to plain vanilla [Basic Paragraph] or the like.

Note: some of these screen grabs are squished to the point of illegibility, but just click on them for the full-size versions.

Create a few character styles to make text stand out. I like to apply a thick underline and shift it up so it looks like highlighting.

Select the text frame containing your vanilla text.

Create a new paragraph style and go to the GREP Style options. Arrange the dialog box so you can see the whole text frame. Make sure the Preview box is checked.

Click on New GREP Style, select one of your character styles, and start experimenting with expressions. Expressiomenting, if you will. Just type in the To Text field, and click anywhere in the general vicinity (outside the field). The character style will be applied to whatever your expression matches so you’ll immediately see what InDesign thinks of your GREP.

This is a nice alternative to entering the expression in Find/Change pressing Find Next repeatedly, because you get to see everything your expression matches at once. Plus, you can compare multiple expressions at the same time, and control the display of the match. You can even write (brief) comments to remind yourself what the expression is matching. Just put the comment inside (?#    )

I just wish we had more than one line of space to work with in the dialog box. We have to get this thing opened up in CS5.

Speaking of space, the (?x) at the start of each expression allows me to put spaces in the expression to make it more readable. It also saves me from errors that would result if I accidentally typed a space. Not such big deals with these short expressions, but a lifesaver with the more complex ones. Then if you need to include a real space in an expression, use the Unicode value: \x{20}. Big thanks to Peter Kahrel’s GREP in InDesign CS3 for that one.

Also be aware that when comparing expressions that match the same text, the lower character style wins out.

There are a few limitations to this whole idea of GREP-styles-as-teaching tool.

First, there’s no place to try out a Change To expression. For that, you’re back to Find/Change, or Rorohiko.

Footnotes aren’t included.

Matched locations can’t be highlighted. So for example, if you use ^ to select the start of a paragraph, you won’t see the highlighting until you add something extra to highlight an adjacent character.

Hard returns won’t be highlighted, so you might want to make a character style that can change the appearance of the return character, like change the point size, scaling, or baseline shift, etc.

When you have the expressions you want, you can copy and paste them into the Find/Change dialog. Or keep them as illustrated versions of saved queries. Start a GREP collection. Trade with your friends.

Until Adobe adds a Preview option to the Find/Change dialog box, I think this is a pretty good alternative to help you get your GREP on.

Mike Rankin

Mike Rankin

Editor in Chief of, InDesign Magazine, and Author of LinkedIn Learning courses on InDesign, Illustrator, GIMP, Inkscape, and Adobe Dimension.
Mike Rankin

Latest posts by Mike Rankin (see all)

  • - November 30, -0001
Related Articles

15 Comments on “Adventures in GREPland

  1. Awesomely sweet tips there Mike! I especially love the “commenting” tip. Where did you pick that up?

    I know of one other tip that might be handy. If you preface the GREP expression with an asterisk, it tells InDesign to ignore the GREP style. It even works with your (?x) trick.

    That way you can duplicate the GREP Style and try different tweaks of it without actually deleting it. Just put an asterisk in front. Or it’s a way to save a bunch of GREP Styles in the same paragraph style but turn them off/on at will.

  2. Thanks Anne-Marie :)

    The commenting tip also came via Mr. Kahrel. I bought his O’Reilly Short Cut when GREP was an interesting/hobby kind of thing for me, but I never finished reading it.

    Now GREP’s become an absolutely necessity for me. I have to format and customize completely unstyled RTF into many different versions in ID, using as few resources as possible. So GREP and the FindChangeByList script are my new BFFs. And my copy of GREP in InDesign CS3 is well-worn (and much admired).

    Love the asterisk tip!

  3. Mike,

    Very nice tip indeed. I used a variant: create a highlighting character style, enter that in the Change Format pane of the Find/Change dialog, enter a GREP expression, and press Change All. Ctrl+Z to undo.

    But your tip combined with Anne-Marie’s asterisk trick is much better: nice way to compare variants quicly. Thanks


  4. Mike-

    My adventures in GREPland may need a little hand holding. I need to find specific text and apply a character style. Not rocket science and it works in Find/Change GREP tab very well. I can’t get FindChangeByList to find multiple product names (single and multiple word) which I am led to believe it was meant to do. The documentation for FindChangeByList is sparse, to put it mildly. Cari Jansen’s article is no help. All I get for my effort is an error message “Java Script Error! Error Number: 25., etc.” I’ve looked over the code until I’m blind. So please check this out an let me know if I’m nuts or not.

    grep {findWhat:”adobe creative suite[‘]s|adobe creative suite”}
    {appliedCharacterStyle:”Product Name Italic”} Find all adobe creative suite product
    names and make Italic.

    I’ve tabbed between like I’m suppose to. No joy.

  5. Mark-

    Would it make you feel better or worse to know that your expression works for me in FindChangeByList?

    The only difference I can see is that I’m using AppleScript and you’re in Javascript. I don’t know what the Javascript rules are for escaping characters, maybe that’s it.

    In general, I also had all kinds of problems with FindChangeByList until I started using BBEdit to work with the txt file, and I could see my invisibles. Are you sure there’s not a return after “product”? Good luck.

  6. Mark,

    It’s not clear where those smart double-quotes came from, but if they’re in your original, that’s the cause of the problem.


  7. Mike and Dave ,

    Thank you for your help. Coding is the bane of my graphic design existence, since the Math school was no where near the Art school at college and we had no computers then. It is not that I can’t do it once I get the straight info on how (learned HTML in a weekend). It is just so nit picky frustrating sometimes and I have no one to go to but here.

    I used Notepad to make the file, so it really is straight quotes, it is this blog editor that won’t let me place straight quotes.
    I still get ‘Java Script Error! Error Number: 25., etc.’ I looked for any special characters that might have crept in. I’m using ID CS4 on WinXP. I’d try it on my Mac at home but I don’t have CS4, only CS.

  8. Hmm. I can?t figure out how to stop Word Press from curling the quotes. (I thought the ?code? tag would work, but it doesn?t. Neither does the ?blockquote? tag.) I even copied/pasted from Text Wrangler where I was certain they weren?t curly, that didn?t work either.

    We?ll check to see if we can fix this. Thanks for your patience.

  9. Thanks Anne-Marie,

    OK. I figured it out. I tried adding the ‘all’ and ‘once’ option like Cari said and I got error messages saying the option was incomplete. I figured since her article was Nov. 05 and I was on CS4 that things had changed quite a bit in my version. So I looked at the sample txt file and just added the {wholeWord:false} option at the end before the comment and that did the trick (what ever ‘wholeWord:false’ means). This is maybe something that could use more of a current write-up. I understand Olav wrote this and his input would help and I’d be willing to to do the drudge work.

    This is my biggest pet peeve with programmers, they must figure everyone else thinks like they do. It reminds me of a utility someone wrote to import EPS files into PowerAnimator years ago. The programmer never wrote a manual or guide to the features and short-cut keys so when the company lost contact with him and the staff who knew this program left, they couldn’t figure out how to get EPS art into their projects. Maybe they upgraded to Maya ($50,000 a seat back then) to solve it.

  10. thanks for this tips. this is a great help for all the people working on their online works. keep it up

  11. OK, I got FindChangeByList.jsx to work exactly the way I wanted it to after looking through the Scripts forum at Now it works great! You just need to make sure everything is perfect. First, make sure all your styles are spelled the same in the script text file as in the Styles Panel. Then open the ExtendScript Toolkit (ESTK), not from within InDesign but from Windows Explorer (I’m on WinXP) and it somehow initializes things. You can also shut down and restart InDesign if things aren’t working. Worked perfect after that.

    I got it to find the exact text string formatted in the exact style sheet and change the text to a character style, per our in-house style rules. Huge time and headache saver.

    One caveat though, Java script does not support some GREP functions at all. I was trying to find specifically styled paragraphs with no period at the end and place a period there ? Find/Change worked (and I saved it!) but FindChangeByList.jsx didn’t.

  12. So, I am a newbie to GREP (watched a bunch of the tutorials and am trying some of it out), and have a question… I want to target URLs and apply a character style. Is it possible to set a GREP style to target http (when it appears), www (when it appears) and characters separated with the “dot” (e.g. in .com)?

  13. Can a grep style or grep search know how many tab leaders before the next text. For example I need at least 4 leaders before the next text after the tab with leaders.

Leave a Reply

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