6 Replies Latest reply on May 6, 2013 3:21 PM by [Jongware]

    Need help with a GREP expression

    gfrederickk

      Seems like this should be easy, but I've lost hours of my life to it already. Any suggestions will be much appreciated.

       

      The type examples:

       

      Best bets for the weekend: This is a line of type, which follows a colon and ends in a period, question mark or exclamation mark. Could be more than one sentance. Details, Page 21

       

       

      This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. Details, Page 21

       

       

      I need a GREP expression that will:

       

      -- When the type is begins with a colon precede (first example), apply a "bold" character style to the type up-to-and-including the colon. I'm defining a colon precede as type leading into an instance of a colon, followed by a space --- which occurs before any sentence-ending punctuation (., ?, !).

      -- Will NOT apply the character style if there is not a colon precede (second example).

      -- Will apply the same "bold" character style to the last sentance in the paragraph -- but only if that sentence does not end with punctuation. This will bold-face the page reference.

      -- It would be preferable to incorporate this functionality into one paragraph style.

       

      Thanks for any help.

        • 1. Re: Need help with a GREP expression
          [Jongware] Most Valuable Participant

          Working from memory (jus' browsing on my iPad so I can't readily test it):

           

          1. Add a GREP style like this:

           

          ^[^.?!]+:

           

          and have it apply your Bold character style.

           

          2. Add another GREP style:

           

          (?<=[.!?] )[^!?.]+$

           

          and have this apply Bold as well.

           

          > It would be preferable to incorporate this functionality into one paragraph style.

           

          You can have as many different GREP styles as you want in each paragraph style. (Although your computer fan may start whining after the fifth or so.)

          • 2. Re: Need help with a GREP expression
            gfrederickk Level 1

            Thank Jong. Much appreciated.

             

            Your penalty: another question. I have one more variable:

             

             

            This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. seemywebsite.com


             

            In this case, the period in the web address seems to throw off the expression. Of course, my attempts to modify what you've done result in chaos. Thoughts?

            • 3. Re: Need help with a GREP expression
              gfrederickk Level 1

              Actually. I'm able to accomodate for this other variable with another GREP expression. Thank you Jong. Again, Much appreciated.

              • 4. Re: Need help with a GREP expression
                [Jongware] Most Valuable Participant

                Sounds you forgot the space in #2:

                 

                (?<=[.!?] )[^!?.]+$

                 

                (it's right there, before the closing round parens).

                .. If you have that, I'd need my computer to test on :-)

                • 5. Re: Need help with a GREP expression
                  gfrederickk Level 1

                  Thanks Jong.

                   

                  When I include the space, I get:

                  This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. seemywebsite.com

                  (Only the .com is bolded)

                   

                   

                  When I delete the space, I get:

                  This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. seemywebsite.com

                  (Nothing bolded)

                   

                  So I added another expression to handle web addresses.

                  • 6. Re: Need help with a GREP expression
                    [Jongware] Most Valuable Participant

                    gfrederickk wrote:

                    When I include the space, I get:

                    This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. seemywebsite.com

                    (Only the .com is bolded)

                     

                    When I delete the space, I get:

                    This is another example, which is not precede by a colon. It could be more than one sentence, which ends in a period, question mark or exclamation mark. seemywebsite.com

                    (Nothing bolded)

                     

                    That still doesn't sound right As I thought, my first idea works fine:

                     

                    Screen Shot 2013-05-07 at 12.12.28 AM.png

                     

                    Anyway, I misunderstood you on the topic of the web address. I thought it was bolded by my code, and you didn't want it to; but instead the reverse is true.

                    But, yeah, you are still better off with another GREP just to handle those.