Skip to content

Instantly share code, notes, and snippets.

@harshithjv
Last active August 6, 2020 13:46
Show Gist options
  • Select an option

  • Save harshithjv/4f76d9dda00c10e3d5a2 to your computer and use it in GitHub Desktop.

Select an option

Save harshithjv/4f76d9dda00c10e3d5a2 to your computer and use it in GitHub Desktop.
Simpler Python Regex object to validate crontab entry time format string.
validate_crontab_time_format_regex = re.compile(\
r"^{0}\s+{1}\s+{2}\s+{3}\s+{4}$".format(\
r"(?P<minute>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<hour>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<day>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<month>[\d\*]{1,2}([\,\-\/][\d\*]{1,2})*)",\
r"(?P<day_of_week>[0-6\*]([\,\-\/][0-6\*])*)"
) # end of str.format()
) # end of re.compile()
@x200595
Copy link
Copy Markdown

x200595 commented Aug 6, 2020

Hello they are a probleme for example if the crontab are:
0 7 * * 1,2,3,4,5,8
(validate_crontab_time_format_regex.match("0 7 * * 1,2,3,4,5,8").groupdict())

result:
{'minute': '0', 'hour': '7', 'day': '', 'month': '', 'day_of_week': '1'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment