Link to home
Start Free TrialLog in
Avatar of mj62mj62
mj62mj62

asked on

egrep YYYYMMDD

Hello,

Does anyone have an egrep regular expression (regex) for valid dates in the format YYYYMMDD?

It's fairly simple for basic checking, for example the DD bit could be:
[0-3][0-9] but that doesn't catch invalid days like 38.

if I write a full regex, starting with ^ and ending in $, I can then use the | (the OR option) along with a second full regex to capture the two cases of [0-2][0-9] and [3][0-1], however that is quite long. (ie. ^<full regex>$|^<second full regex>$)

Ideally I'd like to be able to do an embedded OR within a single regex to capture that 29 is a valid day by 39 is not.  But I can't figure out how to do that.

Of course, something that captured leap years and fancy stuff like that would be awesome, but I'm not holding my breath on it. :)

Thank You,
MJ
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mj62mj62
mj62mj62

ASKER

Impressive :)

Thanks a million,
MJ