6 Replies Latest reply on Sep 2, 2011 6:39 AM by Argonaut777

    GREP styling quandry

    Argonaut777

      Hi,

       

      I'm having problems with a piece of GREP styling for a paragraph.

       

      The issue is as follows:

       

      I've got a long paragraph of information which is punctuated by coloned subheaders. There are no paragraph breaks between the entries and the next subheader, only a normal space. Each subheader is different in word count and some entries have more than 1 sentence.

       

      I used the following simple GREP to apply a 'bold' style to the subheaders:

       

      (?<=\.).+?:

       

      This finds the colon and any text before it fine, but the positive lookbehind for the fullpoint to stop the styling gets confused if there is more than one fullpoint (ie more than one sentence) in the previous entry, and will include all text after the first fullpoint in the previous entry as well.

       

      ie, a section that is:

       

      ... end of previous entry. Another: Blah, blah. Blady boo. Next one: Boohoo. ...

       

      Is giving me:

      ... end of previous entry. Another: Blah, blah. Blady boo. Next one: Boohoo. ...

       

      Instead of:

      ... end of previous entry. Another: Blah, blah. Blady boo. Next one: Boohoo. ...

       

      It appears the GREP is seeing the first fullpoint (after 'blah' as the important one and not the one closest to the colon (the one following 'boo').

      Unfortunately, trying to use the shortest match codes before the lookbehind seems to break the GREP entirely.

       

      So, the question is:

      Is there anyway of making a positive lookbehind (or equivalent) that first fullpoint before the colon? Or am I in cloud cuckooland with this one?

       

      This has been driving mad all week, because it seems simple, but this new to GREP man can't seem to crack it!

      I've tried lots of combinations and even attempted a second GREP style to undo the error in the first one, but this caused its own problems.

       

      Thanks for any help/pointers and thanks for looking even if you can't.

        • 1. Re: GREP styling quandry
          La0s Level 1

          Hi, i am no expert in GREP but had a similar thing not long ago.

          Give this one a try: (?<=\.)[^.\:]+(?=:)

           

          Here you can find some good help:

          http://www.jongware.com/idgrephelp.html

          http://blog.gilbertconsulting.com/2009/12/grep-lesson.html

          http://indesignsecrets.com/grep

          • 2. Re: GREP styling quandry
            Argonaut777 Level 1

            You sir are a star!

             

            That worked perfectly.

             

            I will now sit down and figure out why and be much the wiser for it!

             

            Thank you La0s!

            • 3. Re: GREP styling quandry
              La0s Level 1

              Great, but i cant take all credit for this one.

               

              I got help with solving my own quite similar GREP problem with this tutorial:

              http://blog.gilbertconsulting.com/2009/12/grep-lesson.html

               

              If you follow the description i think you will understand it.

              The other links i mentioned you are also great.

              1 person found this helpful
              • 4. Re: GREP styling quandry
                Argonaut777 Level 1

                Thanks La0s,

                 

                I now know how it works and why (and also why I couldn't do it).

                 

                I was looking for a 'not' expression but couldn't find one.

                I was using a codes examples PDF from jetsetcom.net and it lists the ^ as the expression for 'beginning of a paragraph' in InDesign, rather than as a 'not' expression.

                 

                I found the escape \ before the : in the character set doesn't seem to be needed, as : isn't a metacharacter, as far as I know?

                I've taken it out and the GREP seems to work fine without it, unless I've missed something.

                I've also dropped the lookahead for the colon too, as I wanted to include it in the styling.

                So my final GREP looks like this:

                 

                (?<=\.)[^.:]+:

                 

                I thought I'd post it so that if anyone else has a similar query they can see GREP I used.

                 

                It's also interesting the the . in the character set doesn't have to be escaped to make it work, as it would normally signify any character, rather than a fullstop as I think it does here?

                 

                Again, a big thank you for your help and website references, I really appreciate it!

                • 5. Re: GREP styling quandry
                  [Jongware] Most Valuable Participant

                  Only FYI, because you already got it to work:

                   

                  I was using a codes examples PDF from jetsetcom.net and it lists the ^ as the expression for 'beginning of a paragraph' in InDesign, rather than as a 'not' expression.

                   

                  Correct -- but only in the usage you are using it in, as the very first code inside a character set. In this expression

                   

                  ^At the beginning there was the Word ...

                   

                  it does mean 'beginning of a paragraph'. As the first character inside a [ .. ] set, it's a negation of the set.

                   

                  I found the escape \ before the : in the character set doesn't seem to be needed, as : isn't a metacharacter, as far as I know?

                   

                  Usually it isn't. (It is under other circumstances: inside expressions in combination with the (?..) notation, but never on its own.)

                   

                  It's also interesting the the . in the character set doesn't have to be escaped to make it work, as it would normally signify any character, rather than a fullstop as I think it does here

                   

                  Correct. The full stop (period) always acts as a 'match anything' character, but when on the inside of a curstom character set it loses its magical properties. The same goes for * and ? and a couple of other meta-characters. On the other hand, there are a few codes that suddenly are special inside a group. You already encountered one of them: ^ (but only at the start of a group). Some other examples are the Dash (a-z is "everything from a to z") and uh... well there are a couple more.

                  1 person found this helpful
                  • 6. Re: GREP styling quandry
                    Argonaut777 Level 1

                    Thanks Jongware for your explanation, was very helpful, especially on the ^ usage!