is now part of CreativePro.com!

GREP and Text Metacharacter Cheat Sheet

23

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.

Anne-Marie “Her Geekness” Concepción is the co-founder (with David Blatner) and CEO of Creative Publishing Network, which produces InDesignSecrets, InDesign Magazine, and other resources for creative professionals. Through her cross-media design studio, Seneca Design & Training, Anne-Marie develops ebooks and trains and consults with companies who want to master the tools and workflows of digital publishing. She has authored over 20 courses on lynda.com on these topics and others. Keep up with Anne-Marie by subscribing to her ezine, HerGeekness Gazette, and contact her by email at [email protected] or on Twitter @amarie
  • Michael says:

    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.

  • Eugene Tyson says:

    That’s quite cool, thanks for sharing :-)

  • Aaron says:

    This looks very helpful. Thanks, Mike!

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

  • Nicolas says:

    I’ve never heard of GREP, what is it?

  • adam says:

    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)

  • Peter Kahrel says:

    Adam: in the Find What field, type two spaces followed by +
    In the Change To field, type just one space.

  • Eugene Tyson says:

    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.

  • @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!

  • Eugene Tyson says:

    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?

  • Dave Courtemanche says:

    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?

  • Eugene says:

    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.

  • Eugene says:

    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

  • @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.

  • Eugene Tyson says:

    David, no problem about the code thing.

    This is the link to the find between that could help

    https://creativepro.com/findbetween-a-useful-grep-string.php

  • 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

  • I should add that TEX-EDIT PLUS is, for the present, a Mac-only application.

  • adam says:

    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

  • johnny says:

    this program is something like a science lab for people who really love GREP its currentlly PC only but it basically allows you you to PROGRAM and TEST any regex (aka GREP) search strings

    https://www.regexbuddy.com/download.html

  • Carsten Pihl says:

    Since we still use CS2 (sic), anyone nows if the text-metacharachters work with cs2?

    Nice to use in the find/change script that I use a lot.

  • Martin Fischer says:

    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? (https://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 https://indesign-faq.de/index.php/was-bedeuten-die-grep-wildcards-im-detail/

    There you will find a PDF: https://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

  • din67 says:

    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.

    • Spaceman says:

      Hi din67. I’m sure you’ve found a way to do this by now as your post is from 2013 but just in case you didn’t (and for anyone else looking for something similar). You can easily use a GREP style to automatically fix this for you. Just add a GREP Character Style to your Paragraph style and use (?<=\()\w*?(?=\)) as the expression. This will change any single word between ( & ) into whatever style you want. This will not alter any other text in perenthesis in your paragraph which contains more than one word. :)

  • >