0

So I am trying to find a smart way of writing down how to recognise this particular range of time:

HOUR: an hour with the formats HH:MM or HH:MM:SS and values between 08:31:12 and 23:21:10 (correct examples are: 08:31, 23:21:09, 12:54:51)

Do I really have to do through all the possibilities like (08":"31)(":"(1[2-9])|([3-5][0-9]) )? | (08":"3[2-9])(":" [0-5][0-9] )? | and so on... (pretty long)

Is there a smarter way to handle particular ranges like this example? Thanks guys

  • 6
    Smart way here consists in not using a regex :) Parse it and check with available DateTime methods. – Wiktor Stribiżew Sep 01 '15 at 13:39
  • @stribizhev you mean I should parse a normal hour like a canonical hour = [0-2][0-9]":"[0-5][0-9](":"[0-5][0-9])? and then after in the parser everytime I retrieve a token hour I check if it is in the range I need? And if it's not? – Andrea Sep 01 '15 at 14:57
  • You can use [`\b\d{2}(?::\d{2}){1,2}\b`](https://regex101.com/r/nG7pK5/1) and then parse the value obtained. – Wiktor Stribiżew Sep 01 '15 at 16:45

0 Answers0