Skip to content

Instantly share code, notes, and snippets.

@lennax
Created February 13, 2012 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennax/1821483 to your computer and use it in GitHub Desktop.
Save lennax/1821483 to your computer and use it in GitHub Desktop.
import re
units = {
'day': 'd',
'hour': 'h',
'minute': 'm',
'second': 's',
}
# Matches only valid data (I hope)
# String format substitution to improve flexibility
valid = re.compile(
r"""\d+ %(day)s \s # 1 or more days
(1?\d | 2[0-3]) %(hour)s \s # 0-19 or 20-23 hr
[1-5]?\d %(minute)s \s # 0-59 min
[1-5]?\d %(second)s # 0-59 sec"""
% units, re.X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment