Copy link to clipboard
Copied
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.
This is what you have now:
d+\[a|p(m)]?
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
...Copy link to clipboard
Copied
This is what you have now:
d+\[a|p(m)]?
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.
Copy link to clipboard
Copied
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:
9am-5pm
8:30pm-10pm
7:25am-11:30am
It worked beautifully.
Copy link to clipboard
Copied
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!!