python regex for current time -


i having trouble regex seems in creating regex matches time in format "hh/mm/ss". making alarm clock in python.

here's have:

import time, re  time_pattern = re.compile(r'([0-2][0-4])/([0-5][0-9])/([0-5][0-9])')  alarm_set = input("set alarm time (hh/mm/ss): ")  while not time_pattern.match(alarm_set):      print('invalid input. must expressed in "hh/mm/ss"')     alarm_set = input("set alarm time (hh/mm/ss): ") 

but reason when try match '18/00/00', doesn't match. have no idea why isn't working. because matches '24/59/59' , '00/00/00' fine. weird because me, regex seems fine.

any appreciated =)

it doesn't match 18/00/00 because match hour using:

[0-2][0-4] 

you fix using

[0-1][0-9]|2[0-4] 

instead.

a better approach might use strptime instead of using regex.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -