Strange GREP behavior

Learn / Forums / General InDesign Topics / Strange GREP behavior

Viewing 5 reply threads
  • Author
    Posts
    • #71283

      I have been using GREP and GREP styles and thought I was fairly good at it…until this morning. I have a job that comes to me as simple text. and have to apply the styling to all the questions within paragraphs. Something easy enough to do with a GREP find/replace. The paragraphs open with a question. That can be addressed with a nested character style in the paragraph style. \

      The GREP expression I am using for rest of the questions: ((?<=\.).*?(?=\?)\?)

      In English, I want to find any characters from a period (but not the period) until a question mark is encounter and add the question mark to the marked subexpression.

      My expression works on all but one instance and I can’t figure out why. Here is the text that I am working on.

      AROMA NATURALS /// SOY VEGEPURE® CANDLE – ASSORTED SCENTS
      WHAT IS IT? 100% natural soy candle with essential oils and pure plant aromas. HOW DO I USE IT? Simply light the lead-free candle wick and enjoy. WHY IS IT IN THE BOX? Made from 100% pure plant aromas and natural vegetable waxes, they are as good for the environment as they are for you.
      CALBEE /// LIGHTLY SALTED SNAPEA CRISPS
      WHAT IS IT? Tasty baked, lightly salted snapea crisps made from 70% whole pea. HOW DO I USE IT? Open, eat, and bask in the glory of your healthy eating. WHY IS IT IN THE BOX? It’s the perfect natural snack. Snapea crisps have less fat, more fiber, and lower sodium than regular potato chips.
      THESIS BEAUTY /// EYE SERUM
      WHAT IS IT? Superbly moisturizing organic eye serum. HOW DO I USE IT? Apply morning and night on moist skin just below the eyebrows and under eyes. WHY IS IT IN THE BOX? Made from certified organic oils and all-natural vitamin E, this serum is a lullaby for your skin.
      JOYFUL BATH CO. /// ‘NILLA BUTTERMILK® RENEWING BATH SOAP
      WHAT IS IT? A seriously wonderful-smelling handmade botanical soap. Soul?soothing vanilla mingles with skin?softening buttermilk and its natural emolients. HOW DO I USE IT? Wash your hands and smell the goodness this soap has to offer your senses. WHY IS IT IN THE BOX? Handmade and hand-cut, this natural bar is preservative?free. Rinses clean and smells good, too!

      The problem is that on the last “HOW DO I USE IT?” GREP selects all the way back to “Soul-smoothing…” If I delete that sentence the GREP works fine. I thought it might be related to the “-“(hyphen) but it works elsewhere when there is a hyphen in the sentence preceding the question.

      Can anyone see what I am missing”

      Regards,

      Ken

    • #71291
      David Blatner
      Keymaster

      Why not use (?<=\.)(.*?\?)

    • #71308

      Thanks David for the reply. Your expression fails in my document at the same point as mine.

      I rekeyed the paragraph in a new InDesign document and both of our expressions fail at the same point.

      Somehow this behavior is related to the sentence before it as I stated above. I deleted a word at a time and it wasn’t until the whole sentence and the period was deleted that it behaved in the manner I expected.

      Now, looking at my post and the text I copied from the document, I notice the hyphenated words are sometimes supported with a hyphen and in the problem sentence they show up with “?”‘s. I retyped the sentence with no hyphens just full words and GREP still grabs the entire sentence in addition to the question.

      As long as there are not too many pages I can style the questions manually but as the quantity grows that can be inconvenient.

      • #71309
        David Blatner
        Keymaster

        Ah, I see what you mean now. Try this:
        (?<=\.)([^.]+?\?)
        Notice that instead of the dot (which means "any character"), I'm typing [^.] which means "anything except a dot/period"

    • #71315

      Thanks again, David. That didn’t work either. I don’t expect this forum to be a conduit to you and have you solve my problems.

      Referring to my archives and my copy of O’Reilly Shortcut by Peter Kahrel, “GREP in InDesign CS3/4” I got this to work for all questions in the above text.:

      ([\u\s]+\?)

      In other words find a class of characters containing only uppercase characters and white space one or more times and follow with a question mark.

      This should work in my paragraph style with a GREP style changing the character style on the marked expression to a Demi weight.

      Thanks again for your help.

    • #71628
      Chris Court
      Member

      Hey Kenneth,

      I’m no black-belt in GREP, but I may have an answer your question as to why your original style is failing on the specific case you mention.

      Your GREP style looks for any characters that lie between a period and a question mark, and apply a character style to this text, up to and including the question mark. Now, you will notice that in the paragraph where your style fails, there is a second period, immediately before the word “Soul”. Your GREP sees this first period, and sees the question mark, and styles everything in between, including the first sentence and the second period.

      The following GREP should identify only the text you need, correctly… (?<=\.)[\w\s]+\?

      It seems as if David’s second GREP SHOULD work, but for some reason it doesn’t. Not sure why.

      C

    • #71634

      Thanks Chris for your input.

      It was helpful because it caused me to look at the word “Soul.” Looking back at the original post I now notice that when I copied and pasted the original text from InDesign there is something different about the two hyphenated words compared with all the other instances of hyphenated words in other paragraphs. These hyphens show up here online as question marks. Other hyphenated words show as hyphens so something is different about them.

      When I redefined what I was looking for as a string of uppercase characters and spaces ending with a question mark GREP ignores all the rest.

      If the dust ever clears around here, I will try to find out what is different about those two hyphens compared with “lead-free”, “all-natural,” “wonderful-smelling” and “hand-cut.”

      Until then, my thanks for your input is all I can give.

      Ken

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
>