fork(4) download
  1. import re
  2.  
  3. p = re.compile(ur'^(\d+d)?\s*((?:[01]?\d|2[0-3])h)?\s*((?:[0-5]?\d)m)?$', re.MULTILINE | re.IGNORECASE)
  4.  
  5. time = input("Please enter your value: ")
  6. if re.match(p, time):
  7. print("\nGreat " + time + " is a valid entry.")
  8. else:
  9. print("\nOups... " + time + " is NOT a valid entry.")
Success #stdin #stdout 0.02s 9024KB
stdin
"1g 8h 30m"
stdout
Please enter your value: 
Oups... 1g 8h 30m is NOT a valid entry.