Friday, 27 September 2013

match portions of an optional section

match portions of an optional section

I have a regex set up to match a US-formatted date and time. It looks like
this:
/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2})(am|pm|AM|PM|Am|Pm)/
However, I need it to also match dates that do not contain the time
component.
How do I modify this, so that if it's a date, I get 3 matches, and if it's
a date-time, I get six?

No comments:

Post a Comment