poliander / cron

Parse and validate crontab expressions in PHP
https://github.com/poliander/cron
GNU General Public License v3.0
63 stars 10 forks source link

Suggest to use regular expression to check cron rule #1

Closed taichunmin closed 9 years ago

taichunmin commented 9 years ago

Hello, Sorry, I am not a native English speaker. I read the repo's source code. This is what I need. But this code can use regular expression to check cron rule more faster. This is my regular expression: ^((\d+|(\d+-\d+|\*)(/\d+)?)(,(\d+|(\d+-\d+|\*)(/\d+)?))*|[a-zA-Z]+)$.

poliander commented 9 years ago

Thank you very much! Speed is not really an issue here - but 100% compliancy to the current crond implementations is absolutely a must. It is AFAIK not possible to achieve this using regular expressions, e.g. your expression does not look for abbreviated month names or week day names. If you dig in deeper, you will understand.

Also, the validator does not only validate an expression, but also prepares the internal properties for later processing using getNext() and isMatching().