Any task scheduler or automation system will have Cron syntax. This simple set of rules allows users to define when a task should be run. Oftentimes, Cron will follow the Unix standard for specifying the time by minute, hour, day, and month. This post will help anyone needing to match Cron Time Expressions using regular expressions.
/(((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7}/
Matches:
- 0 * 14 * *
- 45 23 * * 6 /home/oracle/scripts/export_dump.sh
- 1 0 * * * printf “” > /var/log/apache/error_log
This regex matches valid cron time expressions with predefined scheduling macros and @every durations.
/(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})/
See Also:
- Date (dd/mm/yyyy) Regular Expression
- 12-Hour Time (hh:mm:ss) Regular Expression
- 24-Hour Time (HH:mm:ss) Regular Expression
- Month Regular Expression
- Regular Expression To Match Names Of The Days Of The Week
- Regular Expression To Match Month Name
- Regular Expression For Year
- RFC 2822 Date Format Regular Expression