9 Replies Latest reply on Feb 14, 2012 12:01 PM by Peter Spier

    GREP style – apply up to a point

    flaming1 Level 2

      Hi

       

      We run a catalogue with products that often have part of their range excluded, and the style for product descriptions is to have everything after the word 'Excludes' in italic.

       

      We use a GREP style Excludes(.+\n)*.+\r to apply italics from the word 'Excludes' onwards, and it works very well.

       

      For example we may have a description like "Company Name Cheese Slices 250g Excludes Low Fat Slices", so our GREP style applies an italic style on just "Excludes Low Fat Slices".

       

      A new situation has arrived where there may now be some content appearing after the 'excludes text' where we don't want the italic style applied. The new text will always begin with a dollar sign, but I cannot work out how to stop the GREP style at that point.

       

      So the description may now be "Company Name Cheese Slices 250g Excludes Low Fat Slices $1.50 each or". We want the 'Excludes Low Fat Slices" to be picked up and italicised with the GREP style, but don't want the "$1.50 each or" at the end to be affected. We just want that to stay in the original style, unitalicised.

       

      I guess it's a case of telling the GREP style to stop whenever it encounters a "$" after "Excludes" but I can't work it out.

       

      Is it possible to do this?

       

      Thanks

      Steve

        • 1. Re: GREP style – apply up to a point
          Peter Spier Most Valuable Participant (Moderator)

          Is this the first time that a $ appears? If so youcan use a second GREP style to apply [no style] to the $ and following.

          • 2. Re: GREP style – apply up to a point
            [Jongware] Most Valuable Participant

            Add

             

            (?!\x{24})

             

            after the + in the expression you have. This is a negative lookahead -- the current character should not be followed by whatever is inside the parentheses (so this text will not be included in the expression).

             

            In this you cannot use '$' because the dollar sign itself is a GREP code -- End Of Line --, and the regular escaping of special meanings -- precede it with a backslash -- is known to fail for the dollar sign. (But you can always test if (?!\$) works for you, as it's ever so slightly more obvious what you are doing .)

            1 person found this helpful
            • 3. Re: GREP style – apply up to a point
              flaming1 Level 2

              Thanks for the suggestions Jongware. I haven't got it working yet, but I'll persevere. Pasting in your addition to the expression doesn't seem to work, but it may be that I have to modify my original expression as well somehow.

              • 4. Re: GREP style – apply up to a point
                flaming1 Level 2

                Thanks Peter. If I try a second expression as you suggest, is it able to 'undo' what the first expression has already done. In that  the first expression has already applied italics right through to the end of the description, so the second expression would have to override that?

                 

                I'll give it a go regardless and see what happens.

                • 5. Re: GREP style – apply up to a point
                  flaming1 Level 2

                  Running a second GREP style to pick up everything after the dollar sign worked a treat. Thank you!

                  • 6. Re: GREP style – apply up to a point
                    [Jongware] Most Valuable Participant

                    A-ha, I was thinking too simple. This turned out to be one of the more challenging ones

                     

                    Your own expression appeared unnecessary complicated, by the way, because by default *all* GREP searches run to the end of a paragraph (which you here explicitly indicated using '\r'). However, I wondered what that '\n' was doing there in a group of its own. Apparently you may have insert any amount of soft line breaks, and it took me a while to find the cases where your GREP does not work without the explicit soft line break in the search but with a soft line break somewhere in the text:

                     

                    cheeseslice.PNG

                     

                    This optional line break is a bother -- regular GREP sees it as the end of a paragraph, just like the hard return. (And you probably found that out the hard way as well.) A solution is to force GREP into Single Line Mode, where it ignores the special end-of-the-line meaning of both \n and \r and treats them as regular characters, so . will find them. But this adds a new problem: what about the \r at the very end? Fortunately because this is a GREP style you don't have to build in an extra check for the \r code -- GREP styles always stop at the end of a paragraph.

                    So finally

                     

                    (?s)Excludes(.(?!\$))+
                    

                     

                    worked for me , that is, a sequence of characters where each single one is not followed by a '$' sign.

                    1 person found this helpful
                    • 7. Re: GREP style – apply up to a point
                      Peter Spier Most Valuable Participant (Moderator)

                      Very slick. You're still the master at this...

                      • 8. Re: GREP style – apply up to a point
                        flaming1 Level 2

                        Cool, thank you Jongware, that is indeed very slick.

                         

                        I suspected that it should be possible to get it working elegantly like this (no disrespect intended Peter), but it was beyond my abilities.

                         

                        Thank you for sharing your knowledge.

                        • 9. Re: GREP style – apply up to a point
                          Peter Spier Most Valuable Participant (Moderator)

                          I don't feel offended or disrespected in the least. Jongware is the man for this stuff.