fork download
  1. import re
  2. rx = r"(\d+):(\d+)(?:-(\d+):(\d+))? (.*)"
  3. strs = ["12:30 Test", "12:30-12:50 Test"]
  4. for str in strs:
  5. m = re.search(rx, str)
  6. if m:
  7. print(m.groups())
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
('12', '30', None, None, 'Test')
('12', '30', '12', '50', 'Test')