30
Finding Time Values
Time values are tricky. They should fit this format, although the 12- and 24-hour versions are different:
00:00 xx
But we must take account of the range of values. The trick is to divide and conquer. The leading zero is optional, so the ?
operator helps with the first digit. The second digit is problematic, but this will match 0
to 23
including whether we also have 00
as well:
[01]?[0-9]|2[0-3]
The minute values range from 00
to 59
and are matched with this:
[0-5][0-9]
Putting it all together with the colon and adding seconds values we get this:
([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])
For a 12-hour clock with ...
Get Developing Quality Metadata now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.