21 Replies Latest reply on Jan 8, 2013 1:29 PM by Joel Cherney

    GREP code help

    smashkirk Level 1

      I have a bunch of paragraphs like this:

       

      Cycling (Mountain)

       

      Jun. 22 (Sat)  The North Face Rundle’s Revenge. Calgary. www.transrockies.com

       

      Jul. 29-Aug. 2 (Mon-Fri)  TransRockies Challenge. Calgary. www.transrockies.com

       

      Sep. 7-8 (Sat-Sun)  2013 Johnson MS Bike Tour. Hinton. www.msbiketours.ca

       

       

      Is there a way to use GREP code to format the dates that are in bold? From the begining of the line, to the last ")". But I don't want to format the section heading "Cycling (Mountain)".

       

      Any help would be appreciated.

       

      Thanks,

       

      Ak

       

      PS. This forum is awesome and has helped me a ton in the past!

       

      Also, is this considered a scripting question? Should I have posted this under the Scripting section?

        • 1. Re: GREP code help
          Joel Cherney Adobe Community Professional & MVP

          Seems straightforward to me.

           

          Untitled.png

           

          Are there other conditions that narrow the focus? Because I've cast a pretty wide net, here.

          1 person found this helpful
          • 2. Re: GREP code help
            Peter Spier Most Valuable Participant (Moderator)

            Nope. That's going to pick up that first paragraph, too.

             

            I think you need something like:

            ^\U\l\l \.\d.+\)?  [there's a space between the second \l and the \.]

            • 3. Re: GREP code help
              smashkirk Level 1

              Wow you're fast!

               

              That worked, but not perfectly.


              I should clarify that my text is not currently bold in InDesign. I just used bold in my question to show what text I want to target.

               

              The code you provided works, except when there is another parenthesis in the same paragraph, such as this:

               

              Sep. 7 (Sat)  Super Spartan Red Deer. 14k(8+ Miles) Super Spartan with 20+ obstacles.  This event will have many trials to push any competitor to their limits. Heritage Ranch, Red Deer. www.spartanrace.com

               

              So, in the above paragraph, I want to format just this text "Sep. 7 (Sat)". Keep in mind some paragraphs look like this:

               

              Jul. 29-Aug. 2 (Mon-Fri)  TransRockies Challenge. Calgary. www.transrockies.com

               

               

              Thanks!

               

              Ak

              • 4. Re: GREP code help
                Joel Cherney Adobe Community Professional & MVP

                I tested it first, Peter. The first paragraph is not bold.

                • 5. Re: GREP code help
                  smashkirk Level 1

                  I tried Peter's code ^\U\l\l \.\d.+\)? but it doesn't find any matches.

                  • 6. Re: GREP code help
                    SJRiegel Adobe Community Professional & MVP

                    This looks like a job for Nested Styles.

                     

                    If the paragraphs you need to change share a paragraph style, it will be even easier.

                     

                    If not, you can make one and then apply it.

                     

                    Nested Styles

                    Charater style :Bold  through one )

                    • 7. Re: GREP code help
                      Peter Spier Most Valuable Participant (Moderator)

                      Well you should check again, because it is here. maybe you limited the scope?

                       

                      My expression should probably be modified slightly to account for 3-character month names (i.e. May) that don't get abbreviated:

                       

                      ^\U\l\l\.* \d.+\)?

                       

                      but for some reason it isn't finding anything. I'll be back.

                      • 8. Re: GREP code help
                        smashkirk Level 1

                        Nope, none of my text has any current styling applied. I want to target some text and apply a style to it. Thanks though.

                        • 9. Re: GREP code help
                          Joel Cherney Adobe Community Professional & MVP

                          Aha! Yeah, that would be more complicated.

                          smashkirk wrote:

                           

                          I tried Peter's code ^\U\l\l \.\d.+\)? but it doesn't find any matches.

                           

                          Peter forgot that \U means "anything not uppercase" - he meant \u "anything uppercase."

                           

                          In your example, you separate the parenthetical date from the entry with two spaces. If this is rigorously enforced throughout the document, then something like

                           

                          \u\l\l\..+\) 

                           

                          will catch only "uppercase, lowercase, lowercase, period, then anything up to the parenthesis, space space." But then your document must be perfectly free of double spaces after close parentheses.

                           

                          But SRiegel's answer is the best so far. No need for GREP when Nested Styles will always pick the first parenthesis, whereas GREP will always be maximally greedy and consume text up to the last find-able parenthesis.

                          • 10. Re: GREP code help
                            Peter Spier Most Valuable Participant (Moderator)

                            Yeah TWO typos, the \U needs to be lowercase, and the space is inthe wrong position.

                             

                            ^\u\l\l\. \d.+\)? should work correctly.

                            • 11. Re: GREP code help
                              Peter Spier Most Valuable Participant (Moderator)

                              Crud. Left out the asterisk.  And the question mark is in the wrong place.

                               

                              This works, I promise:

                               

                              ^\u\l\l\.* \d.+?\)

                              • 12. Re: GREP code help
                                Joel Cherney Adobe Community Professional & MVP

                                Well you should check again, because it is here. maybe you limited the scope?

                                 

                                Nope, "Cycling (Mountain)" is absolutely not bold over here. I blame Jive.

                                 

                                Anyhow, your fixed GREP query does a pretty good job, I think. I would still want a nested style instead, in case someone decided to use Sept. instead of Sep., or if May doesn't have a period after it.

                                • 13. Re: GREP code help
                                  smashkirk Level 1

                                  Peter, it works flawlessly! (post #11 that is).

                                   

                                  Amazing. Thanks so much! This saves me a ton of time.

                                  • 14. Re: GREP code help
                                    [Jongware] Most Valuable Participant

                                    > ... whereas GREP will always be maximally greedy and consume text up to the last find-able parenthesis ...

                                     

                                    Peter's allowing for that. The modifier "?" right after the period toggles Non-Greedy behavior.

                                    • 15. Re: GREP code help
                                      [Jongware] Most Valuable Participant

                                      I meant to say after the + (it's a modifier of *, +, and ? as well as {[min],[max]}).

                                      • 16. Re: GREP code help
                                        smashkirk Level 1

                                        I'm not too familiar with nested styles so forgive me. As I mentioned, none of my text has any styling applied to it. How can I use nested styles if it currently has no style applied? Just curious.

                                        • 17. Re: GREP code help
                                          Joel Cherney Adobe Community Professional & MVP

                                          Yeah, I figured that out and trashed a post. It also catches May - I didn't know you could use the asterisk like that, I've been using ??

                                          • 18. Re: GREP code help
                                            Joel Cherney Adobe Community Professional & MVP

                                            A Nested Style would apply any character style to text that satisfied the conditions you placed on it - but I think that Peter's last GREP query is now a better solution. It does a good job of limiting the query to keep it from grabbing too much.

                                            • 19. Re: GREP code help
                                              Peter Spier Most Valuable Participant (Moderator)

                                              I could have used the ? instead of * in that location, but the * actually allows for 0 or MORE, so it's more forgiving.

                                               

                                              All of this depends on a reasonably good formatting of the text to start with. Two spaces before the digit would break it, as would none. you could allow for that by using ^\u\l\l\.*\s*\d.+?\) I suppose.

                                              • 20. Re: GREP code help
                                                Peter Spier Most Valuable Participant (Moderator)

                                                Joel Cherney wrote:

                                                 

                                                A Nested Style would apply any character style to text that satisfied the conditions you placed on it - but I think that Peter's last GREP query is now a better solution. It does a good job of limiting the query to keep it from grabbing too much.

                                                You could use the query to appply a GREP style, though, to avoid the need for Find/Change.

                                                • 21. Re: GREP code help
                                                  Joel Cherney Adobe Community Professional & MVP

                                                  I am writing "I will always use WhatTheGREP before posting" on the chalkboard 1000x times