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

5 Cool Things You Can Do with GREP Styles

I love GREP Styles in CS4. I’ve said it before: It’s probably my favorite new feature, and although it’s small, I think it makes the upgrade very worthwhile. But what are they, how do you make them, and what can you do with them?

A GREP Style is a way to apply a character style to some text inside a paragraph, based on a GREP pattern. GREP, as we’ve discussed, is a way to describe a text pattern using codes. For example, you can write “all the words that start with a and end with e” with the code \<a\S+?e\>

You can use GREP in the Find/Change dialog box, but only manually — that is, you have to actually do a search and replace each time you want to apply the formatting. GREP Styles don’t change text at all; they only apply formatting. But there are many things you can do with just that.

To apply a GREP Style to a pararaph, you probably want to edit your paragraph style definition. (You can apply a GREP Style to a single paragraph as local formatting by placing the cursor in the paragraph and choosing GREP Styles from the Control panel menu. But I find that in general it’s just more useful using GREP Styles inside a paragraph style.)

To make a new GREP style, click the New GREP Style button:

To apply a character style, click once on Apply Style and it turns into a character style. Then you can choose a style you’ve already made or choose New Character Style if you haven’t made one yet. (That’s another little feature I love in CS4.)

Type the GREP code in the To Text field. For example, the default GREP code \d+ means “one or more digits in a row.”

I encourage you to turn on the Preview checkbox to see how (or if) it works before clicking OK.

Five Cool Things You Can Do with GREP Styles

Okay, enough with the “how.” Now what about “what”. Bob Levine already posted about one way to use them here. Here are 5 more ways I like using GREP Styles. Please feel free to comment below with other ways you’re using this cool feature.

1. Oldstyle Numerals. Apply a character style that applies the OpenType Oldstyle Proportional figure style to all digits in a paragraph.

2. No Break words and phrases. I’m tired of setting individual words to “No Break” or changing dictionaries to instruct InDesign not to break words. If I don’t want to break “InDesign” on to two lines, I’ll just apply a no-break character style to the GREP code “InDesign” (that’s pretty simple grep, eh? Just type the word!)

3. Change Width of Em Dash. In some fonts, the em dash is just too wide for my tastes. No problem. Make a character style with a 75% (or whatever) horizontal scale. Then apply it to the em dash character. Don’t know how to type an em dash code? No problem. Just click the icon to the right of the To Text field. That shows you all kinds of cool codes for things.

4. Make OpenType Fractions. Jamie McKeee reviewed and explained the excellent Fraction script in the recent issue of InDesign Magazine. I added a little sidebar to that review before it went “to press” that explained that if you are using OpenType fonts that include the Fraction style, you can apply them with a GREP Style. Apply a “Fractions” formatting character style to the code \d+/\d+ (which means one or more digits, followed by a slash, followed by one or more digits.) It won’t work if you have commas or decimals in the fractions, but it’s a good start! (Of course, you could make a GREP code to handle those situations, too?)

5. Make Characters Disappear. My colleague and co-author Olav Kvern just wrote me, saying, “You really don’t need to find/change typical typewriter text entry errors (double spaces after periods, etc.) anymore–just make a grep style that does it and make it part of your base paragraph style(s).” Wow. Good point! But how to make a character disappear when you can only apply formatting? Make a character style that applies the fill color of None, a tiny point size, and a horizontal scale of 1%. Boom, it’s “gone.”

Dang, I can’t stop at five. Here’s one more you might find useful:

6. Replace text with icons. What if you want some text to convert into a special character? For example, everywhere you type some normal text, you want it to change into a special icon in a particular font. Here’s the before and after:

I found the ornament/symbol/glyph I wanted could be typed with the number “4” in Bodoni Ornaments. So then I made up a little easy-to-remember code that would never show up in normal text: “4z”. I then added two grep styles. The first one was 4(?=z) which means “look for the character 4 but only when it has the letter z immediately after it.” I applied my bodoni ornaments character style to that. The second grep style was (?<=4)z which is “find the letter z, but only when it has the number 4 before it.” To that, I applied my disappear character style.

What do you think? Can you think of other cool uses for this excellent feature?

David Blatner

David Blatner

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at are among the most watched InDesign training in the world. You can find more about David at
David Blatner

Latest posts by David Blatner (see all)

  • - November 30, -0001
Related Articles

140 Comments on “5 Cool Things You Can Do with GREP Styles

  1. Hi Jongware,

    Peter Kahrel’s chaining script is actually what will work for me best. Thanks for turning me on to it.


  2. I’m about to embark on investigating using GREP styles for our business, we are involved in text book publication and I’ve been trying to find a way to apply different text colours for nested styles in different chapters or on different pages, rather than needing a new style for each colour

    e.g. one spread will be grammar and all the text styles will be green

    the next page will be vocabulary, all the stylesheets should match exactly except the spread colour is red, so the headings, underlines and exercise numbers change from green to red.

    the next is blue then back to green again etc etc (these vary but the principal is the same, we don’t want to make these changes manually or create a different document for each spread).

    my question is, does GREP recognise page numbers or sections?

    wish me luck!

  3. Hello everyone, I have one problem with GREP style, I cant figure out how to configure it to work right.

    In document there are used different chemical formulas, so that means some numbers are subscript, others superscript…

    the problem is that here: 109/l number 9 should be superscript style – 10(9)/l

    I can get it work that 9 is superscript after digit, but don’t know hot to stop it before / sign.

    One more question, where could I get some more info on GREPs – like which “formula” means what..

  4. I am producing a brochure with acronyms including CO2. Is there a quick way to get the 2 in CO subscripted automatically? So far I do it by hand and it’s very tedious and miss some…

  5. Thanks, Jongware. Isn’t that amazing that people so often write a comment without looking at the comments that have gone before them? Jean-Marc, I don’t mean to pick on you, but just look at the two comments before yours! :)

  6. First off, let me say that GREP is COMPLETELY foreign to me and I really just don’t understand it. So figuring out if GREP can be used for what I am needing is really confusing.

    I have three different block quote Paragraph Styles that I use. We almost always put a space before and after the block quote but not between the paragraphs within the block quote. I have the block quote styles set to automatically add a space before and after so that I do not have to manually do this. Because the before and after space is added with a hard return and when there are multiple paragraphs within a block quote, I do have to manually remove the space. This is very time consuming. I would love to be able to have this space not appear WITHIN my block quote styles and instead only before and after them.

    Can I use GREP to solve this?

    Thanks in advance for any help! (We are a non-profit organization that publishes books. None of us have any “formal” InDesign training, although we have been using it for years and I just know there are ways to work smarter that we still haven’t figured out!)

  7. Hi!

    I’m new to GREP concept and I have this small repetitive task I have to perform and I’m sure the GREPs are my solution. Here’s what I have to do…

    I need to change this formating:

    …to this kind of format:

    Thank you for helping me!

  8. have a great one for anyone who has to change Mclaren to McLaren and the like:


    to find the lowercase letter which should be uppercase; then

    in the style, make sure that the character style is All Caps.

    doesn't sound like much, but when faced with a database of thousands using data merge, applying the style to the surname entry corrects the entries on the fly rather than fixing them in the d'base itself.

  9. I’ve run into an issue with a project where I need to all caps the running headers. With some titles containing registered trademarks.

    When pulling data from the paragraph title style (with superscript registered trademarks forced via GREP), the running header style overrides the superscript and makes the registered trademark large again.

    I tested to see if turning off the paragraph all caps style would allow the superscript GREP style to work, but it didn’t superscript either. However, if i set the paragraph style to superscript all without all caps on, the entire text superscripted.

    Is there a known issue with superscripting individual characters in running headers, or does anyone know of a solution? I’m completely scratching my head on this one. Thanks!

  10. Aaron: the issue at hand is that automatically picked up text such as your running header cannot be selectively formatted. Compare it to attempting to format the first digit of a two-digit automatic page number.

    There is this plugin called “Power Headers”, which I think does allow selective formatting; I usually just forget the automatic way and do it ye olde style: manually.

  11. I thought that might be the case, but was hoping for an automatic solution. Fortunately, if i need to manually do it there are only a handful of chapters in the 300 page technical book that need it. Thanks for the quick response Jongware! BTW, fantastic info here for the chemical GREP styles. Will save me loads of time.

  12. Is anybody still reading this? Hope so. I am not a professional, I am merely laying out a small book for my club (Nevada Native Plant Society). Its all laid out (with some prior help from these forums, thankyou very much), but the problem now is: need the scientific names in the photo caption boxes and text to appear italicised in the index. It seems that I have to learn about GREPS and I have been doing so. The most useful text for understanding how to build expressions was Michael Murphy’s GREP in InDesign CS3 which has examples in color with detailed but simple explanation, as well as explanation of overall principles of assembling GREP expressions. The best one for showing how to incorporate it in a paragraph style was Using GREP Styles in InDesign by Jennifer Jones. The abovecomments are to help out other people in my same boat.

    The other reason I am writing is to ask you experts: what would the metacharacter be to refer to text that is italicized? Can’t find it anywhere. I found caps but not that.

    Then am I right that having the code I need, I need to follow a procedure like that described for subscripts/superscripts and Index Entries and Subscript/Superscript and David Blatner’s Auto Format Superscript and Subscript Numbers using GREP Styles.?

    BUT a set of instructions that describes exactly what I want to do would be just ducky! Including where to put what, and how to run the index to reflect the modifications. It would save me countless (unpaid) hours. Can anyone help me with that? All the future users of our little book will thank you………

  13. Hey pat4141,
    I haven’t tested this but I wondered if you just needed to restrict your query by including a character style (italic) in the Find Format box?

  14. Hi David and group,
    Thanks for this and your previous columns.
    I’m a newbie working with a lot of text with an older version of InDesign. Two things eat up a lot of my time:
    1. Vertical justification (I had to snap the text to baseline and manually review each page to make sure the text’s top and bottom lined up on each double-page spread;
    2. Now I’m battling my way through the proofs, mainly hunting down the “runts” (widows/orphans). This is darn annoying, made easier with DPT Tools. I still have to manually correct each.

    Are both these things more easily accomplished in CS5 and later, through GREP? I know you have a vested interest in DPT Tools, but I still thought I’d ask.

    Thanks very much in advance.

  15. @David, Thanks for answering.
    So what you’re saying is, CS6 can find and fix the runts but not manage justification, right?
    DPT Tools also seems to find the runts but not do justification. “Optical justification” with the flowing text from my novel seems to balance one double-page spread but throw another page off.
    I apologize if I’m asking in the wrong forum. Thanks for your help.

  16. Can GREP automatically put R (superscript) and TM (superscript) after certain words such as “Windows” or “MAC OS”? If so, can it be taught to do this only in the first occurrence of the word and none of the subsequent?


  17. @Angela
    Grep Styles cannot add characters it can only format them. It can change WindowsTM
    to Windows?, but not add the ? for you.
    Auto Correct can’t handle “fancy characters”

    But you could combine the 2 functions
    First Auto correct Windows to WindowsTM then grep it.

    NOTE that auto correct is not style specific and grep styles are so this is not a great solution unless you want all the paragraph styles to do the grep and then you would have to setup the grep style on every style or base style. (easier to add the ? manually)

    A simple text / grep find / change will do the trick
    I made quite a nice (if I say so myself) script that processes a word list (made in excel (or any text editor – word, wordpad saved a tab delineated txt file) or stuck in the script) this is not a dynamic solution but with a keyboard shortcut can be very effective.

    The script is here

    Hope that helps


  18. @Angela:

    Sorry I missed the point about the first occurrence.

    The grep to change the first occurrence in a paragraph of Microsoft to Microsoft?
    would be find:
    change to:
    to find the first occurrence in the story would be a lot more complicated to grep but easy to script.

    I think the most sensible solution is that when you want Windows to be followed by a superscript r of TM would be to type Windowsr or Windows Tm with the following grep style

    To have every Windows trademarked would be bonkers!!


  19. I have a very large document with figures in a parentes which is a reference number i.e. (1). I need to change all reference numbers in the parantes to oblique. Is there an easy way to find and replace?

  20. Hi all,

    I have a large document with lots of fees in tables and I have been asked to include the Pound sign (£) in front of all the fees. Is there a grep code that can find any number (eg 1,356) and place a ‘£’ in front of it?



  21. I am creating certificates where the line has to read something like this
    on this 2nd day of… where the nd after the 2 needs to be a superscript. Or 3rd, 4th etc. I was able to get the 2 to superscript, but don’t want that. Is there a way to do that? Anyone know? Currently I have 400 certificates to do. I’d prefer not to have to go thru manually.


    • Daliah,

      Perhaps you have already resolved your issue so I hope this solution will help others dealing with similar problems:

      1. Create a new Character Style
      2. Select the “Basic Character Formats” menu and choose Super from the Position menu.
      3. Create a new Paragraph Style
      4. From the GREP Style Menu, choose New Grep Style
      5. Select your Character Style
      6. Where it says To Text:, paste the following string:
      7. Select Ok to save your new Paragraph Style
      8. Apple your Paragraph Style to the text.

      This works with Find/Change too. See the following weblink for more information:

      Good luck!

  22. I’m trying to do simple ‘initial uppercase’ (sadly not included in ID basic character formatting) for words in a header – been trying GREP but no success:
    1.create all caps character style
    2.edit the affected para style
    3.create a grep style
    4.Apply Style: that all caps character style
    5.To Text: \ Beginning of Word)

    The beginning letter of each word remains lower case. –

    -The source character style is definitely all caps.

    -Preview is on.

    -The edited para style character format is set to Case: Normal.

    Surely this common formatting need is possible w grep – what am I missing? thanks!

  23. Sorry, somehow typo on step 5; should be:

    5.To Text: backslash left carat (menu picks are Locations – Beginning of Word)

  24. just wanna ask if there’s a grep expression that can make a paragraph which have a 1 letter 2 line drop cap to 2 letter 2 line drop cap??
    the paragraph starts with a (Single|Double) quote >> “This | ‘This.
    is it possible for grep to span the drop cap to 2 letters 2 lines instead of only 1 line which drop caps only the quotation mark.

    thanks for future comments.. ^^
    and i enjoy using grep styles and expressions in my work ^^

  25. I have the following file with the multiple IP’s listed in the format below. Is there a way that GREP can format the output to just display IP and any ports that contain http for each IP in the list?

    Host: () Ports: 80/open/tcp//http///, 139/open/tcp//netbios-ssn///, 515/open/

  26. Hi.
    In my file used of two language (Arabic and English). Arabic is Primary Language.
    How can i define GREP for English language that is used in the Arabic language paragraphs until apply “EnglishCharacters” style to any formats. like upper case, lower case, … .

  27. (\s\w+){2}[[:punct:]]*$

    Add No Break style to this to force the last 3 words in paragraph to not break – replace the number 2 to any number of words you want to not break, -1:

    (Any space+any word) * X + (any punctuation and multiple spaces if they are they are there or not) at the end of paragraph

    • Hi Chris,

      I tried to do this however I am unable to get it to work for me. I have placed the string in one of my Grep Styles. Is there anything else I need to do?

  28. I double checked and actually I was wrong:

    + “No Break” = Force the last 2 words in paragraph to not break apart, try inserting the “[[:punct:]]” part by using the menu and not typing it?

  29. Hi Chris,

    Thanks. I downloaded your GREP Test.idml file and have things working, sortof… I noticed this GREP expression stops working when I have any of the following conditions:

    a space before the paragraph marker
    single or double quotes near the text prior to the paragraph marker
    commas near the text prior to the paragraph marker

    Is there anyway to include these within that GREP expression?

    • Hi Greg – sorry for really late reply

      To include the conditions you listed replace with the following GREP code:


      This should include all punctuation or white space you may have before the end of paragraph marker

  30. I’m looking for an expression to change numerals into text ie, ‘1’ becomes ‘one’, ‘2’ becomes ‘two’ etc.
    I want this to be part of a nested style. Is this possible?

    Alternatively, turn a list number into text, so a paragraph list number ‘1.’ becomes ‘one’. Possible?


    • Hi Matt,

      I doubt this can be done with Grep Styles. See above, it states “GREP Styles don’t change text at all; they only apply formatting.”


      • Right, this is beyond what the GREP styles are meant for. You could use Find/Change (changing only one number at a time), and for lists you could use a custom text. All manually, unless you think way out of the box, and create a font in which the character ‘2’ looks like “two”. (I imagine that with some fancy ligatures you can also make ’10’ look like “ten”.)

  31. Hello sir.

    I’m Khairul from Malaysia.

    I’m searching on how to italic letter that unitalic in italic word.

    Word “Writing”
    Letter “W” is regular,
    Letter “r” is italic,
    Letter “i” is italic,
    Letter “t” is regular and so on.

    How can I make them all italic?

    I’m working on a book that has this problems in many words.

    Please help me. Sorry for my english.

  32. Is it possible to search for any spaces BEFORE a specific character style (even if the spaces aren’t that style) and change them to a single EN space? I’ve been messing around with GREP for the last week or so and have been able to do some amazing things with it, but I just can’t figure this one out.

  33. I am working for a client who has an InDesign CS6 document that is already formatted. The booklet has more than 500 phone numbers that need to be click-to-call when exported to PDF. I have used GREP to insert tel:# in front of every phone number, but find that I have to add each hyperlink individually. Is there a way to batch convert all of the phone numbers to hyperlinks?

  34. I am writing a booklet with a schedule of a Science festival. Events are happening in several locations. It would help me a lot if InDesign would detect the street (or square) name and color the whole paragraph containing the name of the street with a specific predefined color.
    For example a typical paragraph would look like:
    5 pm Is it magic or science? Part 1 (John Smith, GB), New square (8+)
    So I would like the paragraph to turn blue if it contains “New Square”

    I am GREP rookie. Please help – it will save me a loooot of time.


    • Miha: the easiest way to do this is just with Find/Change, and you do not even need to use GREP. You can just search for the words “New Square”, then leave the Change To field blank, and then apply the paragraph style with the Change Format field.

    • Hi Miha,

      This following GREP instruction seems to work for me:

      .+New square.+

      I just created a Blue Highlight Character Style and defined the above GREP statement in my Paragraph Style.

      Good luck!


  35. Thank you very much for your help.
    Meanwhile I’ve put together a jsx script that does the street search and changes the colour of the corresponding paragraph.
    All invited to the Science Festival – Sciencetival in Ljubljana, Slovenia:


  36. Hi!
    I have a problem which if done manually takes hours. I want to find two characters which have a space before them and change it to other two characters. Please Help me.
    Find: [space]bc
    Change: [space]dc

    • do you want to do this automatically on the fly? as part of they styling?

      because it seems a simple find/change dialog, searching for every “[space]bc” and replacing it with “[space]dc” — one time — seems like it would be enough

  37. Hi, I know this is an old thread, but it’s the most relevant to an issue that’s just come up.

    This is a tough one:

    I want to use GREP (or anything, really) to change the styling of automatic hyphenation.

    That is, not how frequently or at what part of the word. I want the hyphens that are automatically inserted where words break at the end of a line to use a font different from the body font.

    I’ve been able to use GREP to target manually inserted hyphens, even discretionary hyphens, but not automatic hyphenation. I’ve tried setting my body copy as one font, and using GREP to change every other character (not a hyphen) to a different font, but alas, the auto hyphens take the same face as the text that’s breaking.

    The only solution I could come up with would be turning off hyphenation in the para style and discretionary hyphenating the entire book. So that would be a “no.”

    • David: No, there is no way to change the font of those automatic hyphens. In that situation, I would create a new font based on the font you’re using, then alter the hyphen character inside that new font.

  38. I’m looking for a way to use discretionary line break in a selection, i.e., three characters/letters at a time. I found a code for character by character, find: \w(?=\w), change to $0~k, but am looking for one that would highlight a selection of three or place the line break every three characters within a selection, e.g., in primers, say, 5’‑AATGTTTCTCTTAAAT. Currently, I’m having to do this manually every three spaces, with a shortcut. I would like to highlight the whole batch and automatically have a line break every three characters. Is this possible, and if so, how? Thanks in advance.

  39. I’m working on a project where I have to create two index in the same publication. The objective is to locate the product description/product number (167876 Pasmic OutDry Glove). The first Index is the Numeric one (167876 Pasmic OutDry Glove), which is done. The second is the product one (Pasmic OutDry Glove 167876), which is the one I’m having problem. Is there any way in Grep to select the product number and place it after the product description?

Leave a Reply

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