Help on Regular Expression for Cronjob testing

I need a small test for Cronjob entries...

things like */5 can be ignored

this works...

((\*|(\d(\d)?([,\-]\d(\d)?)*))\s){4}(\*|(\d(\d)?([,\-]\d(\d)?)*))$

i would appreciate any comments
(i am neither an expert in perl nor in regex ....i think in the perl topic i can find the most regex gurus)

so please let me know if this is good

greetz andy
LVL 3
AndyWHVAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
/^\s*\w+\s*=\s*.*/ || /\s*#.*/ || /^\s*\@(reboot|yearly|annually|monthly|weekly|daily|midnight|hourly)\s+.*/  ||
/^\s*((\*|d\d?([-,]\d\d?)*)(\/\d\d?)?\s+){3}
((\*|1?\d([-,]1?\d)*)(\/\d\d?)|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+
((\*|[0-7]([-,][0-7])*)(\/\d\d?)|sun|mon|tue|wed|thu|fri|sat|sun)\s+
.*/xi
0
 
AndyWHVAuthor Commented:
i need the time only (no command...) so the expression may end when all the time is specified...
i modified yours a bit because i experienced errors on months and weekdays with my tests
(\/\d\d?) here should follow always a ? ....like you did in minutes,hours and days, right ?

 /^\s*\w+\s*=\s*.*/ || /\s*#.*/ || /^\s*\@(reboot|yearly|annually|monthly|weekly|daily|midnight|hourly)\s+.*/  ||
^((\*|\d\d?([-,]\d\d?)*)(\/\d\d?)?\s+){3}
((\*|1?\d([-,]1?\d)*)(\/\d\d?)?|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+
((\*|[0-7]([-,][0-7])*)(\/\d\d?)?|sun|mon|tue|wed|thu|fri|sat|sun)$/xi

thank you for this amazing help :-)

now it seems pretty good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.