3 Replies Latest reply on Jul 27, 2017 6:26 PM by r5dsign

    Time formatting with GREP

    r5dsign Level 1

      Hello Community,

      I am trying to use GREP to format the times for  events in a program I am designing. I got it started but for some reason but it is not catching the rest of the time patterns. See attached screenshot. I know I still have to account for the rest of the patterns but this is where I need expert advise on how to do it so that numbers, colons ( : ), dashes ( - ), and morning ( am ) are accounted for.


      Here's my initial attempt: \d+\[a|p(m)]?


      Thank you in advance.

      Screen Shot 2017-07-27 at 4.27.09 PM.png

        • 1. Re: Time formatting with GREP
          [Jongware] Most Valuable Participant

          This is what you have now:




          That is, EITHER one or more digits, followed by a literal(!) open bracket and an 'a', OR a 'p' followed by an 'm' followed by an optional closing bracket.


          What you want is more something like this (untested!):


          ( \d+(:\d+)?[pa]m-?)+


          which is

            a group of

              some digits, optionally followed by

                 a colon and more digits

              followed by either a 'p' or an 'a'

              followed by an 'm'

              optionally followed by a hyphen

            repeated ad infinitum


          The optional hyphen at the end is to cater for "9am-10am", which would be a time, followed by that optional hyphen, then followed once more by the entire oattern but without the hyphen. You can see this if you accidentally entered "9am-10am-" somewhere; the hyphen at the end will also be included.

          1 person found this helpful
          • 2. Re: Time formatting with GREP
            Erica Gamet Adobe Community Professional

            I assume you want everything formatted then, including the hyphen? If so, Jongware's solution is dead on (tested!)...no surprise there!
            I used his expression on the following:





            It worked beautifully.

            • 3. Re: Time formatting with GREP
              r5dsign Level 1

              Beautifully answered!

              At first I thought I was doing something wrong when I tried Jongware's solution but I didn't realize there was an extra space between the first opening parenthesis and the first backward slash that I needed to remove.

              Thank you Adobe community for your input!!