is now part of CreativePro.com!

5 Cool Things You Can Do with GREP Styles

141

I love GREP Styles in InDesign. 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.

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 Proper Fraction script in InDesign Magazine Issue 27. 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 is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Mike Rankin says:

    For my money, GREP styles, IDML, and cross-references are the three best things about CS4.

    Folks should check out the GREP resources page here.

    I’m especially fond of Rorohiko’s GREPTutor. because it gives you instant feedback. You can paste or type some sample text, type in an expression, and instantly see what that expression matches in the sample text.

  • F vd Geest says:

    Let me add this also, for Dutch readers also on my blog:
    https://fvdgeest-dtp.blogspot.com/

    A text about pollution that has CO2 an H2O in it. The 2 has to be subscript and some baseline shift.
    A characterstyle is made that has this baselineshift and subscript and is applied to the GREP styles:

    (?<=CO)2

    and

    (?<=H)2(?=O)

    The (?=O) part because also H2 and H2C is also in the text and this does not need the subscript!

    Added a acronym GREP but this has to exclude the CO in the CO2 part:

    \u\u+(?!\d)

    (thanks to Harb from InTools for this one!)

    One click on the paragraph style and all formatting for acronyms, CO2 and H2O is made.

    For Dutch readers: this is an example of GREP from my book InDesign CS4 wich is released January 20th in the Netherlands. Ful colour, hard cover, 480 pages. See my blog for more information.

  • Klaus Nordby says:

    Wow, David, very cool GREP style tips here!

    I especially liked “3. Change Width of Em Dash” — as them long ems have annoyed me often — but your whole piece is an inspiration to get creative with GREP styles.

  • Dave Saunders says:

    On a Mac, anyway, you can type the actual em-dash character by using Opt+Shift+hyphen.

    I use this GREP style to add space on each side of every em-dash:

    Apply: Track75
    To text: .~_

    where Track75 applies 75 units of tracking. And the GREP means: any character followed by an em-dash.

    Dave

  • F vd Geest says:

    >where Track75 applies 75 units of tracking. And the GREP means: any character followed by an em-dash.

    In Dutch we have many things like:

    blalala ? in between ? blalbla.
    (space, en-dash, space)

    So use tracking also on the en-dash followed by anay character (or in this case: space)

  • Bill Lynch says:

    I’ve found grep styles really handy for automatically applying small caps. This one does it for things like 9am, 9pm or even 9km:

    (?<=\d)[\l\u]m

    This does it for a list of specified abbreviations:

    \b(cd|dvd|mc|dc|gwcc|gaa|b&b|inec)

  • Marc says:

    And we could use GREP styles to create syntax highlighters (useful to layout scripts or snippets).

    Here’s a short example, using 7 rules in one paragraph style:

    BEFORE applying the style

    AFTER applying the style

    The complete story (French):
    https://marcautret.free.fr/geek/ikono/grepcolor/

  • ABC GREEN says:

    Many People Have Requested A way To Use grep styles to use codes to format text and to have the codes disappear. Based On A Few Of The Previous Posts I Think it Is Fairly simple. First Create A grep Style That Includes Your Code, For Example I Use @01 Before The Text And @02 After The Text Which Is A grep Of @01.*?@02. Next Create A Disappearing Character Style Which Is .1 font Size, a 1% Horizontal Scale, a 1% Vertical Scale And Color Of The Paper. Next Make grep Style For Codes To Apply Disappearing Style. Make Sure Disappearing Style Is After Formatting Style. Boom you got what yot want.

  • Igor Freiberger says:

    GREP styles are great. But I never would use them to “correct” usual typo errors. Much better to use a script to achieve this. Or to use Autocorrect feature.

  • Sandee cohen says:

    David,

    You know I’m a HUGE fan of GREP. (I believe you and I were two of the first people to ask for GREP in InDesign many years ago.)

    But I don’t understand your first point.

    Why use GREP to apply Oldstyle to all digits in a paragraph?

    Why not just set Oldstyle as one of the attributes in the paragraph style?

  • Bob Levine says:

    Sandee said: Why use GREP to apply Oldstyle to all digits in a paragraph?

    That’s an easy one, Sandee…because we can! :)

  • ABC GREEN says:

    Referring to my previous post:
    Actually when I started I thought I would be able to add Hidden Text as a property of a character style and it was therefor necessary to place the hide grep style after the format grep style. But if you just use very small text for the code “@01” markers then to indesign it’s still there and the order doesn’t really matter

  • Igor Freiberger says:

    To Sandee: I also got tricked by the first tip. “Because we can” makes no sense to me.

    Later I understood where it can be used. Some typefaces still came in two flavours: oldstyle figures and small caps in one font, lining figures and regular alphabet in other. As I remember, fonts from DTL and Hoefler & Frere-Jones uses this. Of course, this is a situation to be changed with proper OT convertion/usage.

    With GREP you can control this using a character style with the oldstyle/small caps font. So, the paragraph will actually uses two fonts, but in an automatic way, emulating the feature already usual to OT fonts.

  • @Igor: Thank you! Whew! I knew that there had been a reason that I used this on a project, but Sandee’s point was basically right. It wasn’t the OpenType fractions formatting I had applied; it was an Expert font (Utopia in this case). Trick saved!

  • Anne-Marie says:

    Heh. The InDesignSecrets readers (and commenters) are the best, bar none!

  • Ive been playing arround with Grep and Grep-styles for a while and its a really cool feature.

    David suggested I should share the file with you so here is my little christmas present to you… hope its a good one.. All of InDesign CS4 Keyboard shortcuts in a document that you can reformat as you like with ease.. if you´re bored this christmas that is…haha…

    I copied the keyboard shortcuts from the Edit menu/ Keyboard shortcuts and went to Show sets. There you have all the secrets of Indesign shortcuts in a horrible unformated and unrapproachable text.

    So I figured I could do this better by formating this file in one go by using Grep-styles, for easy updating (my file contains the Norwegian shortcuts, but dont worry). Its really easy to update to your language, just copy the shortcut commands set you want and paste it on page 1. …and VOILA…all the text formats with bolds, regulars, hidden text, italics, colours and so on…

    Make sure you also check out the conditional text aswell as you can hide all the commands that are not defined. this is so cool… If you put your text in you need to do a grep search and apply the correct condition to apply this. Ive written a small “manual” on the right side of the page if needed.

    The InDesign file can be downloaded from:
    https://ejak.palografen.no/index.php/blog/mer/indesign_cs4_shortcuts/

    Have a really nice christmas folks!

  • These are great! GREP styles ALMOST convinces me that I should upgrade.

    But I disagree with “making test-editor mistakes disappear.”

    First, why would you want to add a whole layer of complexity by shrinking down and no-filling these, when with a simple GREP or two you can get rid of them all. Makes a messy document.

    Second ? you hand that file to someone else, believe me you they’re not going to know WHAT the heck is going on. I had senior designers at my last assignment flummoxed by text variables ? so I’m sure this would be equally ? er ? flummoxing.

  • I definately see your point Daniel, I too would be really nervous about handing files with grep-styles or even nested styles over to the average designer. I probably wouldnt, without making sure they actually can confirm to me that they know whats in store for them. I guess it has to be filed under the label “because we can”… and its more of a way of showing the power of a technology.

    To be honest I know of designers that wont even use or understand the power of a simple stylesheets (which scares me…). It also seems to me that a lot of people with a background from Quark (sorry…me too) doesnt understand the difference between Character- and Paragraph-styles because theres so little difference in Quark which they were used to (and theyre not updating themselves). A whole set of time-, moneysaving and consistency possibilities is not available for them. If youre just producing one offs, like posters or flyers i wouldnt be too worried. But if youre in a heavy production environment lets say book- or magazine production, it would be plain madness not to use the posibilities that is spread across InDesign.

    Still it doesnt mean that people with the knowledge shouldnt use it for less complicated tasks.

    I had a project were the client would save aprox 97-99% time producing about 3000 adverts a year. This could be done by using the XML-features in InDesign. When you can tell and actually show someone that they can save time, errors and even earn more bucks they are much more inclined to learn the skills necessary (sadly the financial crisis hit the project…nobody seems to need houses these days…).

    To be honest I spent days getting a proper understanding of GREP, and its power (yes, most people would say way too much). Most designers wont spend even 15 minutes with it because lets face it, its not very designer friendly (as a lot of other features in InDesign). I guess it comes down to easy math, if doing something manually takes less time than learning a skill it might be more sensible doing that, than spending hours learning. However if you can spend some time and use the skill over and over it might be worth looking into.

    I also think there is a huge difference in technical needs between InDesign users or markets. For instance (without intending to step on anyones feet):
    – Advertising / Design – less “highend” knowledge generally needed, as they are more focused on good ideas and one off production. (in the end result nobody will see if styles is being used or not). Time and cost of production is not necesary the most important issue, as investments in a good ideas are.
    – Bookproduction – a lot of knowledge is needed, as they have repetition, and massive amounts of information that needs fast and accurate processing. Cost of working hours and timeconstraints is a big deal for them, therefore their interest in automation and everything that speeds up processes.
    -Newspapers – needs extremely fast proccessing and have to be focused on a consistent information structure, many people works on the same product and we want it to appear the same from page to page, day to day. Everything that does things faster, more consistent is worth looking into, because of extreme time limitations.

    I guess point being knowledge is bliss, when needed. And this always comes as the endresult of investing in learning. You just need to find out when to invest. Everything comes with a price.

  • Okay, I’m going to have to agree: I personally would not use grep styles to remove things like double spaces and other text errors. My point wasn’t to say you should do this, but simply to note that you can do it, and that you can make one or more characters disappear. The example could be useful, but I think the “disappear” example in #6 is better.

  • F vd Geest says:

    Using endnotes? Want an Opentype font to apply OpenType superior?

    (?<=.)\d+

    And make a characterstyle that has OpenType superior on.

  • Arle Lommel says:

    Just found this post when I tried to figure out what GREP styles were. I’m a geek so I thought that they had added support for PCRE and MS flavors, or something like that. This is, obviously, much more useful.

    I’d just like to add another very practical example (I hate to say it but many of the examples in the article seem a little contrived to me, although that isn’t a problem for showing possibilities).

    GREP styles allow for a much more flexible equivalent of nested styles. I recently worked on a project where the first paragraphs of sections started with one of two options, depending on the author. They either began with something like “1.2.3. Here’s the section title. Now we go right into the text?” where I wanted OpenType all small caps applied to only the part shown in bold here. Other authors had no numbers and just titles (we didn’t mandate number as part of our format requirements since we have a mix of technical and non-technical authors), but those needed to be in small caps as well.

    Nested Styles were a tremendous help but because there could be (theoretically) any number of digits (including zero) at the start of a section, it was impossible to define a single Nested Style that would work in all cases without using an End Nested Style Here character (which had to be inserted when we received files from authors, either manually or using a GREP search).

    With this new feature, however, I can use the following simple pattern as a GREP style:

    ^([d.]+ )?.+?.

    The ^ binds the pattern to the start of a paragraph and then has an optional unit of any number of digits and periods followed by the shortest number of any characters greater than one (.+? = one or more characters, but the shortest span that matches the pattern) followed by a period. (This pattern is a bit sloppy, but because it’s not used for search and replace, some things I would normally bother with I didn’t here, such as making the group in parenthesis into a grouping-only expression.)

    This pattern is a generalizable one for all headings in this project and means I no longer have to manually apply the End Nested Style Here character. It’s also especially nice because I can round-trip content out to Word when I deal with authors who need to make substantive changes without worrying about the Nested Styles when I export to RTF and bring an edited file back in.

    Hope this is useful to someone else.

  • Dominick says:

    I hate having to use nobreak to stop URLs from hyphenating. I’m going to try using this GREP style:

    (?<=\.)[\l\u]+(?=\.)

  • Jaap Wolters says:

    This one competes for the ‘Shortest GREP Style Contest’?

    Gill Sans is a beautiful typeface, but it’s hardly usable for text with numbers because of the odd shaped number 1 character. It looks the same as lower case l or uppercase i.
    I found an alternative 1 in the Futura, whitch matches the Gill number shapes very well (with some fine tuning).
    You can guess my solution: the GREP ‘pattern’ to look for was the character ‘1’ and ‘1’ the Character style to apply .
    That’s short, huh?

  • töff says:

    I’ve always preferred Adobe’s awesome OPTICAL KERNING over the metrics. However, it screws up the monospacing of digits — for example, especially bad for lining up phone numbers on a business card (I work @ a printshop), or prices on a menu, etc.

    Having just learned about GREP, I made a new character style called “monokern” (nothing more than the kerning style set to “metrics”) and applied it to “any digit” … VOILA! yay.

  • Aaron says:

    Great thread, all!

    Here’s a stumper: C&C Galliard comes with ‘Alt’ versions which have the lovely swashy versions of some characters and ligatures. It’s easy enough to apply a GREP character style for an ampersand, but what about ligatures such as ‘st’ or ‘ffl’? Is there any way to replace several found text characters with a single font character, without doing manual search-and-replace?

  • Anne-Marie says:

    Aaron why wouldn’t you just turn on this option in the Paragraph Style or Character Style panel (OpenType Features > Discretionary Ligatures) for the text where you want to have those ligatures used?

  • Aaron says:

    Hi Anne-Marie,
    This font is pre-OpenType and regrettably, I don’t think Carter & Cone have converted it yet. So as I said, the ligatures are in a separate ‘Alt’ font, each as an individual character.

    It sure is a good candidate for OT treatment, and a beautiful typeface:
    https://www.fontshop.com/fonts/downloads/carter_cone/itc_galliard_cc/

  • A quick note to Igor, above: the H&FJ fonts that come with old-style figures in a separate font now also come in OpenType, where everything is mercifully engineered so that OpenType-savvy applications (and designers!) can access everything under one roof. More info, here:

    https://www.typography.com/ask/recentTopic.php?rtID=86

  • Teri says:

    Is there a way to use GREP to only select the last couple of words in a paragraph? It’d be great if I could auto apply “No Break” to the last 2 words in every paragraph, thereby eliminating the problem of paragraphs ending with a single word on the last line!

  • @Teri: Excellent question! I might pull this one out into its own post at some point, but for now just use a grep style with a character style that applies No Break, and use this grep expression:
    . \w+?[[:punct:]]*\s*$

    In other words: “Any character followed by a space followed by one or more word characters, possibly followed by one or more punctuation characters, possibly followed by one or more space characters… at the end of a paragraph.”

  • Jongware says:

    My favourite GREP style is to automatically highlight table and figure references in text, so I can find the nearest place to put’em.

    * Make a character style called ‘highlite’ — one with a thick underline of about 10 pts, shifted upwards, and in a suitably bright color. Experiment for the best look for your text size.

    * Add this GREP style to your ‘body text’ style. Remember that styles based on that style also inherit this GREP style — some careful handling of your styles means you only have to do this once!

    (?i)(Figure|Table)\s\d+

    and set its character style to ‘highlite’. If you see any abbrevs used for figures, just add them to the list, i.e.,

    (?i)(Figure|Fig\.|Table)\s\d+

    (Note the escape backslash before the period — it’s still GREP syntax, so this is needed for a literal period.)

    Hey, all figures and tables are highlighted! To switch off the highlights, you don’t have to remove the GREP — simply turn Underline off in the highlite style.

  • Patryck says:

    Thank you so much for all the advices.
    I would like to know if it is possible to define a GREPstyle for the «last line» of a paragraph?
    thanks

  • tom says:

    What I really wanted was a grep to use with line styles to underline all the web link/addresses.
    I got this far not really understanding grep that well:
    [https://]*\w+[.](com|co.uk|org|net|gov|edu|info)[/\w+]*|[https://]*(www\.)\w+[.](com|co.uk|org|net|gov|edu|info)[/\w+]*|[https://]* (www\.)[\l\u\d_%-]+@[\l\u\d_%-]+[/\w+]*[.](com|co.uk|org|net|gov|edu|info),
    Its a bit epic and still does not get everything.
    Any ideas?

  • tom says:

    I have since created another query that gets web links, addresses and email addresses:
    ((https://www\.|www\.|https://)\w+(\.|/)(\w+(\.|/))*\w+)|[\l\u\d_%-]+@[\l\u\d_%-]+(\.|/)\w+(\.|/)\w*
    It worked on every variation I could think of and it great for adding a style for example an underline to all web stuff.

  • Anne-Marie says:

    Tom it couldn’t find email addresses or URLs that lack an https:// in my quick test.

  • tom says:

    Hi Anne-Marie, did you copy and paste both lines of the grep query?
    I got some friends to test it and it worked fine for them.
    We are on CS2 and 3 on xp 64bit PC’s.

  • tom says:

    Third times the charm…
    ((https://www.|www.|https://)w*(.|/|@)*(w*(.|/))*w*)|[lud_%-]+@[lud_%-]+(.|/)*w*(.|/)*w*
    I had one too many one or more times and not enough zero or more times. All the examples I had tested on were big urls so my grep requiring multiple dot and forward slashes worked. I didn?t try really short ones so it wouldn?t pick up things like http://www.oneword or abc@def. The new zero or more times seem to have fixed it nicely though.
    Sorry for insulting your intelligence with my previous comment…

  • tom says:

    Argggg! All the back slashes from my post were removed when I edited it so heres the grep with forward slashes:
    ((https://www\.|www\.|https://)\w*(\.|/|@)*(\w*(\.|/))*\w*)|[\l\u\d_%-]+@[\l\u\d_%-]+(\.|/)*\w*(\.|/)*\w*

  • Casey says:

    @Tom

    This seems to work for me. Short, simply, sweet and all encompassing

    Web Address: [\l\u\d:/]+[.][\l\u\d_%-/]+
    Email Address:
    [\l\u\d_%-.]+@[\l\u\d_%-.]+

    In CS4: Stacked in Grep Styles section with email address appears 2nd in the list.

    In CS3: I run the Web Address F/R first, followed by the Email Address F/R to clean it up.

    It tags all the URLs and email addresses in the following text:

    Here is a scenario where various web addresses are scattered randomly throughout a paragraph. Check out http://www.adobe.com/go/learn_id_grep (g1,2,3) for more details on the topic. With the new power of GREP searches one can save time manually formatting text within the document. Email me at [email protected] and I?ll send you, Mr. Jones, my saved queries. Check out https://en.wikipedia.org/wiki/Grep (g1,2) for it?s history in the UNIX world.

    This is some text with a bunch of addresses in it.
    Some variations on email addresses:
    Contact me at [email protected]
    John?s email address: [email protected]
    Some variations of web addresses, also known as URLs:
    Visit us at adobe.com (g1)
    Make sure to check out https://adobe.com (g1)
    Download the installer from http://www.adobe.com (g1,2,3)
    Consult https://www.adobe.com (g1,2,3) for any help
    Source for tutorials on CS3: adobe.com/designcenter/video_workshop/ (g1,3)
    Everything you need can be found at https://adobe.com/designcenter/video_workshop/ (g1,3)
    http://www.adobe.com/designcenter/video_workshop/ (g1,2,3) is a great resource to learn
    If you need help check out https://www.adobe.com/designcenter/video_workshop/ (g1,2,3)
    Grab all the old downloads from ftp://207.232.11.233 (g1,2,3)
    The installer is buried here: ftp://207.232.11.233/adobefiles/indesign/ (g1,2,3)

  • tina says:

    Can GREP search for superscript numbers? I’d like to use GREP Styles to add some space between close quotes and footnote numbers that are already styled as superscript, but haven’t been able to figure it out yet. Can anyone help?

  • Elizabeth says:

    Can grep eliminate repeating text? I am doing an index and the beginning of lines are often exact repeats of the line above. I’ve investigated data merge but haven’t found (yet) a solution.

  • Joanna Beyer says:

    Here’s one for you! (A question, that is!) Can I use a No Break character style to prevent less than four characters as the last line of a paragraph? Really what I’m looking to do is prevent page references in indexes from ending up as the second line of the index entry by themselves.

    For example:

    Instead of:

    Utica Covered Bridge, [linebreak] 102

    we would want:

    Utica Covered [linebreak] Bridge, 102

    Usually we just do this manually, by scanning through and hand-breaking all the lines that have numbers by themselves, but I would be such a hero if I could find a way to use a GREP for it!

    Thanks in advance!

  • @Joanna: A very short line at the end of a paragraph is called a “runt.” I mentioned one way to fix those (with No Break) in this comment earlier.

  • Joanna Beyer says:

    @David –

    Thanks for the quick response. Since I posted, though, I actually came up with my own that’s working perfectly for my specific case of indexes:

    (?<=[[:punct:]])\s(?=\d+$)

    The "punct" finds the commas that precede the page refs, the \s is, of course, the space that I want to actually apply "No Break" to, and the \d+$ for the one-or-more digits of the refs at the end of the graf.

    Woo hoo! This is really my very first foray into GREP, so I'm proud of myself!

    Thanks again!

    Joanna

  • XiaoYi says:

    Need help with multiline match.

    I have tried to match multiline comment with /\*(?s)(.*?)\*/, and it did work in “find and replace”. but when this pattern was in the peragraph grep setting, it didn’t work at all.

    Thank you

  • Jongware says:

    The Singleline and Multiline modifiers simply don’t work in GREP styles. It’s a limitation, yes, but an understandable one …

    (A dirty work-around could be to replace the hard returns inside comments with shift-returns …)

  • Jerry says:

    Can I set up a single GREP expression to remove or modify a number of things all at once? i.e, one single expression to find and change all multiple paragraph returns, multiple spaces between sentences, and even the # # # you get at the end of press releases?

  • Jongware says:

    @Jerry: yes, with the provision that you should be targetting to only replace them with the same item — for example, you cannot search for two hard returns and replace them with one, and in the same command search for lots of hashes and replace them with nothing.

    This will be a convulated GREP because in the case of multiple hard returns, you’ll want to remove all of them except one, the same in the case of multiple spaces, and in the case of the hashes you want all of them removed. The common denominator here is “remove” — which is simply done by leaving the Replace With field blank. As for the search: (disclaimer: it’s 2:09 at night, had an old friend visiting and made it really late talkin’ about the good ol’ days of cutting films and looking for old CRC copies for reprints)

    ((?<=\r)\r+)|((?<= ) +)|(#{2,})

    (Note there are a few spaces inside this expression. Copy and paste, rather then typing it it.)

  • Jerry says:

    Hi Jongware,

    That does some of it, but not a clean sweep.
    I found that if I change (#{2,}) to simply (#), the expression does get rid of the hashes. But it still leaves multiple tabs, when I don’t even want one.

    Thanks for your input.

  • Jongware says:

    Are you sure you want to remove all hash signs? The #{2,} construction only removes them (all of them) when there are 2 or more in a row. Yours will kill all of them, as in “part #1”.

    .. it still leaves multiple tabs, when I dont’ even want one.

    Yah … well … you didn’t mention tabs ..
    Also — are you sure you want to remove all of them? Text separated by tabs *will* run together, won’t it?

    Actually, while it’s doable to do lots of things with a single search-and-replace, you might be better off splitting them into a number of consecutive replaces. You can save each single one, and Peter Kahrel wrote a script to “chain” lots of saved queries.

  • Jerry says:

    Hi Jongware,

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

    Jerry

  • amyg says:

    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!

  • Seba says:

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

  • jean-marc says:

    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…

  • 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! :)

  • Jongware says:

    Uh, David, same goes for me then … :'(

    I googled this because I knew the exact same question came up before.

  • LOL, Theun! Well, we are all guilty of being blind sometimes. ;) No problem.

  • Aimee says:

    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!)

  • Jerome says:

    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:
    (enter)
    word
    (enter)
    word

    …to this kind of format:
    (space)word(space)word

    Thank you for helping me!

  • Jerome says:

    Forget it guys…
    found it!
    Thanks anyways.

  • collywolly says:

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

    (?<=\Mc)[\l\u]

    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.

  • Aaron says:

    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!

  • Jongware says:

    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.

  • Aaron says:

    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.

  • pat4141 says:

    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………

  • Higgi says:

    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?

  • Melissa Yuan-Innes says:

    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.

  • @Melissa: Unfortunately, GREP cannot see where text is on a page, or control the size of text frames or things like that.

  • Melissa Yuan-Innes says:

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

  • Angela says:

    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?

    Thanks!

  • @Angela: Hm. Maybe. Not sure exactly how. I recommend posting on the forums (click Forums above).

  • D Y T says:

    @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 https://forums.adobe.com/message/4610558#4610558

    Hope that helps

    Trevor

  • D Y T says:

    @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:
    ((?=Microsoft(?=.*Microsoft))\s|Microsoft(?!=Microsoft*$))
    change to:
    $1~d
    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
    (?<=Windows)(tm|TM|r)

    To have every Windows trademarked would be bonkers!!

    Trevor

  • Khalil says:

    I just need to know if I can use GREP to correct (widows) on all paragraphs in the book

    Thanks

  • 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?

  • dejiatunwa says:

    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?

    Thanks,

    Deji

  • dejiatunwa says:

    I found this page which helped in case anyone else is interested
    https://blog.rockymountaintraining.com/?p=2969

    Thanks

  • Daliah says:

    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.

    Thanks

    • Greg says:

      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:

      https://creativepro.com/quick-grep-to-superscript-ordinals.php

      Good luck!

  • Nick says:

    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!

  • Nick says:

    Sorry, somehow typo on step 5; should be:

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

  • JC says:

    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??
    example.
    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 ^^

  • Frank says:

    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: 192.168.1.xxx () Ports: 80/open/tcp//http///, 139/open/tcp//netbios-ssn///, 515/open/

  • hadi says:

    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, … .
    thanks.

  • Chris Haynes says:

    (\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

    • Greg Mouning says:

      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?

  • Chris Haynes says:

    I double checked and actually I was wrong:

    (\s\w+){2}[[:punct:]]*$
    + “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?

  • Greg Mouning says:

    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?

    • Chris Haynes says:

      Hi Greg – sorry for really late reply

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

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

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

  • Matt says:

    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?

    Thanks.

    • Greg Mouning says:

      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.”

      -Greg

      • Jongware says:

        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”.)

    • Mike Rankin says:

      Matt I think this is a great use for the Find/ChangeByList script. I’ll write it up as a blog post.

  • khairul hadi says:

    Hello sir.

    I’m Khairul from Malaysia.

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

    Example:
    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.

  • Scott irwin says:

    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.

  • Shad says:

    Is there a grep style for inserting an * at the beginning and end of a word?

  • Melissa says:

    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?

  • Rob says:

    Thanks very much! This was super helpful

  • Miha Kos says:

    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.

    Thanks
    Miha

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

    • Greg Mouning says:

      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!

      -Greg

  • Miha says:

    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: http://www.sciencetival.si

    Miha

  • Muhammad Asif says:

    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.
    Thanks.
    Example:
    Find: [space]bc
    Change: [space]dc

    • David Cardillo says:

      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

  • David Cardillo says:

    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.

  • Bethy says:

    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.

  • Jaime Prieto says:

    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?

  • colin milne says:

    Is there a way to use Grep to search and replace a placed eps icon with text?

    I have created hundreds of pages of tables which use icons as headers. Now I need to change the icons to text descriptors. For example a W eps icon now needs to become ‘Watts’.

    Any help please?

  • colin milne says:

    Many thanks.

    I did come across and try that script.I managed to get the example working but I’ve not managed to amend the script for my use yet.I will try and get help from our web designer tomorrow as I don’t know how to amend script – I’m just a designer :)

    • colin milne says:

      Is there any way of using Find/Change to find a specific spot colour (in an eps graphic)? I know you can use the Object option to search for colours but they don’t seem to pick up colours in placed eps.

      Many Thanks

  • Terrance M. says:

    How would you add multiple texts to be affected by your Grep style?
    Have been able to manage 2, but 5 will not work.

    For instance:
    Apply style: [none]
    To Text: \d+ or \ or example or example or example

    Thank you!

    • gamouning says:

      Hi Terrance,

      Take a look at “Favorite GREP Expressions You Can Use” available from the following weblink:

      https://creativepro.com/favorite-grep-expressions-you-can-use.php

      It provides good examples on how to use the OR statement with GREP:

      Expressing Or

      (Milk|Dark) Chocolate Milk Chocolate or Dark Chocolate
      (m|M)ilk (c|C)hocolate Milk Chocolate, milk chocolate, milk Chocolate, Milk chocolate
      [mM]ilk chocolate milk chocolate or Milk chocolate
      [^m]ilk ailk, bilk, etc., but not milk
      (?i)milk Case insensitive: Milk, milk, mILk, etc.
      colou?r color or colour (the ? means the previous character or expression may or may not be there)

      Good luck!

  • If some one desires to be updated with most recent technologies afterward he
    must be pay a visit this website and be up to date daily.

  • When we make a character style for the GREP style, why doesnt it appear in the paragraph styles? I want to adjust something and as i cant find it i cant adjust. Only solution is to delete style and remake it, that seems bad workflow

  • hadi says:

    Hi.
    how can write script to just find a grep. I do not want to replacing.

    thanks

    • Theunis De Jong says:

      That is not a cool thing to do with GREP styles. You switch them on and they will apply a character style to everything they can. So, look for other options. You may want to ask questions that are not related to this articlein the general forum.

  • andie says:

    Hello!, can you tell me how can i write in GREP style something that allows me to put in bold the first word in the paragraph? I already have the character style and i did it many years ago but can remember how i wrote it. Thanks!

  • Rombout Versluijs says:

    I found this tip from a post here, https://creativepro.com/topic/simple-grep-help-needed-style-furst-word-in-paragraph/#post-76522

    GREP styles under the paragraph style:

    Apply Style: your character style
    to text: ^\w+

    OR

    Nested Styles under the paragraph style:

    • Click on the ‘New Nested Style’ button
    • Select the character style from the first drop down list.
    • Select ‘Through’ or ‘Upto’
    • Type in ‘1’
    • Select ‘Words’

  • Rombout Versluijs says:

    Thanks, was the same as the other, appreciate the example file! nice

  • Yana says:

    Can I use a GREP style to change the case of articles and prepositions in running heads? They all come out initial capped regardless of how I format the Chapter Title or the recto running head style. I also have U.S. in a couple of chapters and it comes out U.s. in the running head.
    Grateful for your advice. Thanks!

  • >