• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Time formatting with GREP

Participant ,
Jul 27, 2017 Jul 27, 2017

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.

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

Views

441

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 27, 2017 Jul 27, 2017

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

...

Votes

Translate

Translate
Community Expert ,
Jul 27, 2017 Jul 27, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 27, 2017 Jul 27, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

LATEST

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!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines