Skip to content

Instantly share code, notes, and snippets.

@orangelynx
Created February 19, 2020 13:29
Show Gist options
  • Save orangelynx/dc153862c97ee2340ff589c8afd77deb to your computer and use it in GitHub Desktop.
Save orangelynx/dc153862c97ee2340ff589c8afd77deb to your computer and use it in GitHub Desktop.
A really overkill regex expression (python) for parsing time deltas.
(?:(?P<years>\d+)\s*y(?:ears?)?)?\s*(?:(?P<months>\d+)\s*mon(?:ths?)?)?\s*(?:(?P<weeks>\d+)\s*w(?:eeks?)?)?\s*(?:(?P<days>\d+)\s*d(?:ays?)?)?\s*(?:(?P<hours>\d+)\s*h(?:(?:ou)?rs?)?)?\s*(?:(?P<minutes>\d+)\s*m(?:in(?:ute)?s?)?)?\s*(?:(?P<seconds>\d+)\s*s(?:ec(?:ond)?s?)?)?$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment