10 Replies Latest reply: Jan 13, 2011 2:34 AM by Green4ever RSS

    GREP advice

    smashkirk Community Member

      I'm completely new to GREP. I will try to learn it over time, but for now I wonder if someone could give me a hand.

       

      I have many paragraphs like this:

       

      5/28/11 (Sat)  Duke’s Epic 8 Hour Series, Opus Spring Relay. A fun filled day for the whole family! Mansfield Outdoor Centre, Mansfield, ON. www.chicoracing.com


      6/04/11 (Sat) - 6/05/11 (Sun)  Trek Store Canada Cup/Ontario Cup. Canada’s longest running and largest National MTB event. Ontario Cup, Canada Cup, and UCI Cross Country event. See the pros and race for fun! Hardwood Ski and Bike, Barrie, ON. www.trekstorecanadacup.ca

       

      Basically I want to apply a style to the dates which are on the first line of each paragraph. So, the pseudo code would be something like: select all characters from the start of each paragraph to the last instance of ")", and apply a style.

       

      I want to apply a character style to make the dates bold such as this:

       

      5/28/11 (Sat)  Duke’s Epic 8 Hour Series, Opus Spring Relay. A fun filled day for the whole family! Mansfield Outdoor Centre, Mansfield, ON. www.chicoracing.com


      6/04/11 (Sat) - 6/05/11 (Sun)  Trek Store Canada Cup/Ontario Cup. Canada’s longest running and largest National MTB event. Ontario Cup, Canada Cup, and UCI Cross Country event. See the pros and race for fun! Hardwood Ski and Bike, Barrie, ON. www.trekstorecanadacup.ca

       

       

       

      Thanks!

       

      Ak

       

        • 1. Re: GREP advice
          Kasyan Servetsky Community Member

          Warning! I'm not an expert in GREP -- other guys on this forum may suggest a better solution.

          Find what:

          (\d{1,2}/\d{1,2}/\d{1,2}\s\((Sun|Mon|Tue|Wed|Thu|Fri|Sat)\))(\s-\s\d{1,2}/\d{1,2}/\d{1,2}\s\((Sun|Mon|Tue|Wed|Thu|Fri|Sat)\))?
          

           

          Change Format: + Bold

           

          P.S. If you are going to use this in script, you have to escape backslashes:

          "(\\d{1,2}/\\d{1,2}/\\d{1,2}\\s\\((Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\))(\\s-\\s\\d{1,2}/\\d{1,2}/\\d{1,2}\\s\\((Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\))?"
          
          • 2. Re: GREP advice
            smashkirk Community Member

            Amazing! Truly amazing!

             

            Thank you so much. I have about 30 pages of listings. This saved me hours of

            formatting time.

             

            Ak

            • 3. Re: GREP advice
              Mary Posner Community Member

              If you're using CS4 or CS5 and this is a routine job, you may want to set this up as a GREP style.

              • 4. Re: GREP advice
                Haakenlid Community Member

                That's a bit overkill.

                This will work as well:

                 

                ^\d.*\)
                
                • 5. Re: GREP advice
                  [Jongware]-9BC6tI Community Member

                  Only if you are absolutely certain the following text doesn't contain parentheses -- or any numbered list at all

                   

                  Kasyan is downplaying his GREP-fu, but he's spot on -- his version will work exclusively and only on the given date or dates.

                  • 6. Re: GREP advice
                    Mary Posner Community Member

                    Thanks, JW, I was just about to post that! The shorter search string works on the supplied text, but it's "greedy" -- it'll apply bolding up to the LAST close-parenthesis in the paragraph.

                    • 7. Re: GREP advice
                      smashkirk Community Member

                      Very interesting. I tried Haakenlid's version and it does work, but not in all cases. Since some of the listings have a parenthese in the body (not just the date) it will select up to the last parenthesis in the paragraph (like Mary said).

                       

                      Also, some of my listings have some A-Z characters in front of the dates, which this method skips.

                       

                      Thanks for the other option though, it's good know!

                       

                      Ak

                      • 8. Re: GREP advice
                        Mary Posner Community Member

                        Do you have a sample of a listing with A-Z characters before the date? When they do appear, is it a consistent/predictable pattern?

                        • 9. Re: GREP advice
                          Haakenlid Community Member

                          It will not trigger on numbered lists if you InDesigns built-in list styles, which I kinda assumed everyone uses.

                           

                          My expression does what was asked for in the original post, but with the addition of only looking for paragraphs that starts with a digit.

                          select all characters from the start of each paragraph to the last instance of ")", and apply a style.

                           

                          Here's another expression that is much more strict, while still not too long. Short regular expressions are much easier to debug and modify.

                           

                          ((\d+/?)+ \(\w+\)( - )?)+
                          

                           

                          Or this (even stricter, will not accept "Monday" instead of "Mon" or "6/04/2011" instead of "6/04/11"):

                          ((\d{1,2}/?){3} \(\w{3}\)( - )?){1,2}
                          
                          • 10. Re: GREP advice
                            Green4ever Community Member

                            paste the below expression in indesign Find/change Grep

                             

                            Try this expression,

                             

                            (\d{1,2}/?)+ \(\w{3}\)
                            

                             

                            the above will not include the hyphen, do u really want to add it? if you want to include try the below one

                            ((\d{1,2}/?)+ \(\w{3}\)( - )?)+