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

GREP and Text Metacharacter Cheat Sheet

InDesign trainer extraordinaire and all-around nice guy Mike Witherell (owner of JetSet Communications in the D.C. area) has put together a handy one-page cheat sheet of all of the text and GREP metacharacters you can use in a Find/Change operation and made it available to any InDesign user. Here’s a small excerpt:

(The Text column is blank if no text metacharacter exists for an entry.)

While I think you can discover most of these just by revealing the submenus to the right of the Find and Change fields in InDesign CS3, they’re cumbersome to navigate through. Also, you can enter a lot of the text metacharacter ones in other places in InDesign, such as the “stop” character field when you’re creating a nested style, and those places don’t have the submenus. If you have Mike’s chart tacked up next to the computer, you can see at a glance what’s available.

Download the “GREP versus Text Metacharacters” PDF (50K). Find out more about Mike and the training firm he and his wife Urszula run by visiting their web site, JetSetCom.net.

Related Articles
Comments

21 Comments on “GREP and Text Metacharacter Cheat Sheet

  1. I think the symbol for “Any Character” is a period … but it’s not obvious with the leader dots running right into it. You need to format the table with some extra tabs to create a gap between the leader dots and the keystrokes.

  2. This looks very helpful. Thanks, Mike!

    A suggestion: Provide a black and white version with darker headings, for better results from monochrome printers.

  3. This is much clearer than wrestling through the menu fly outs.
    The one thing I still have trouble with are double spaces. When I use GREP for double white space it picks up the white space followed by a forced line break or paragraph return.
    I think I’m going to try to make a rule that looks for double white spaces but excludes the formentioned charachters.
    Does anyone know if there is a shorter way to look for double spaces (other than hoping that the article writers don’t do it anymore after you asked them nicely)

  4. Do you need GREP to find double spaces though?

    Traditionally, especially from Word files or similar, a normal find and replace for two spaces and replace with one space usually rids the little rascals.

  5. @Nicolas: Check out indesignsecrets.com/grep for more information on this very cool topic.

    @Adam: In the GREP tab of the Find/Change dialog box, choose “Multiple Space to Single Space” from the Query pop-up menu at the top. Adobe did the work for you!

  6. I find that that GREP search that David mentions removes all the white spaces, e.g., em, en, quarter, hair, etc.

    I just think it’s important that that is known, as you may have purposefully inserted some spacing in your document, perhaps for triggers for nested styles or something and then you import some new text from some external source, and you decide to run the grep, perhaps you choose the whole document to save yourself some bother later on, and then the GREP search replaces all your triggers for your nested styles.

    Bad times.

    The GREP solution of “two spaces and a + replaced by a \s” worked great for me on a trial I ran on my current document.

    Good times.

    Although I wish that I could exclude Tables from the search. It clearly says that it has found things in tables when searching for items, so why can’t I tell it not to search within Tables?

  7. I have a find/change that I am unable to do with my current knowledge set. I was hoping GREP could help, but I’m still unable to figure out how to do it.

    I regularly work on French Canadian materials. In their price lists, they use No (with the “o” in superscript) in lieu of a number sign. Is there a way to Find/Change all instances of No to N(superscript)o?

  8. Depends on whether a space comes after the o or a figure. I’m not sure what way it works there.

    You need to find “No” but not include the N in the find.

    To do this you need to do a positive lookbehind.

    This GREP will find a “o” inbetween the N and a space

    This one is for between an N and a space and a digit e.g., No 1

    All yo have to do then is change the format to superscript, only the o will be affected.

    You just have to figure out what comes in before the o and include it after the equals in this

    (?<=)

    And find out what comes after the o in No and insert it after the equals in this

    (?=)

    Whatever you put in the middle of the two of the above is what will be actually found.

    I think Anne-Marie thought me that in another post on this site. Probably better explained too.

  9. Ok tried to edit the above post and it lost all my grep stuff, even when wrapped in code so…

    (?<=N)o(?=\s )

    Will find all the “o” between a N and a space

    If a digit comes after the o then replace the \s with \d

    or if it’s a space and a digit then put in \s\d

  10. @Eugene: Sorry about the code hassles. Yes, typing code into this site is tricky.

    @Dave: If you’re using an OpenType font, you should check to see if it supports ordinals. For example, in Myriad Pro, you can just apply the Ordinal opentype formatting to the whole word “No” and it will format the “o” the way you want. Same with Garamond Premier Pro. But other fonts aren’t as helpful. In Minion Pro, both the N and the O are superscripted. Weird.

  11. For anyone interested in doing their ?GREPPING? outside of InDesign (who would want to do anything outside of InDesign?), there is a terrific shareware app called TEX-EDIT PLUS by Tom Bender.

    I?ve used it for years to clean up text before pouring it into InDesign. It?s Cleanup Document tool has options to strip carriage returns/line feeds; leading & trailing spaces; replace multiple spaces with tabs; and a lot more.

    But the really great feature is it?s Find & Replace which allows GREP searches and has a pull-down with a couple of dozen prebuilt searches.

    I love the GREP feature in InDesign, but it?s nice to have an optional stand-alone application in your toolbox.

    Steve

  12. Thanks for the tip David. My find code wasnt nearly as elaborate as the Adobe one. Who would’ve thought [~m~>~f~|~S~s~<~/~,~3~4~% ]{2,} could save you so much time

  13. GREP with it’s wildcards would be very fine, if it would work without the known errors.

    You know, wildcard-searches under Windows will find other things than on Mac (e.g. \s \w \l \u \d).

    Posix [[:alnum:]] should be equivalent to [a-zA-Z0-9] and only find ASCII-characters, shouldn’t it? (http://www.regular-expressions.info/posixbrackets.html) But [[:alnum:]] will find non-ASCII-characters like Umlauts (äöü) or ? too. Under Win it will find ß and ligatures like ? and ? or ? (but not on a Mac).

    If you are interested in what wildcards will find in InDesign under Win and on a Mac take a look at Gerald Singelmanns overview in http://indesign-faq.de/index.php/was-bedeuten-die-grep-wildcards-im-detail/

    There you will find a PDF: http://www.indesign-faq.de/wp-content/uploads/2008/04/grep-wildcards.zip

    Hope GREP wildcards will do their job better and equal under Win and on Mac in future releases of InDesign.

    Martin Fischer

  14. In my books I need to put numbers in brackets e.g., (i), (ii) and need to italicise the number (not the brackets) in the bracket. Is there any way out doing it with GREP.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>