4
I’m looking to learn a little bit more about regular expressions. I thought of a good exercise that will be validating whether a cronjob expression is correct or not.
Therefore, the possible combinations below should return true according to the supposed regular expression.
* * * * *
1-15 */5 0,30 * 5
0,30 * * * 1-5
Remembering that all the above numbers represent a valid Cronjob expression.
Another detail is that expression should contain 5 "members" separated by space. These members, as exemplified above, must be according to the represented in the image.
The expression can be evaluated as:
<minuto><espaço><hora><espaço><dia_do_mês><espaço><mês><espaço><dia_semana>
For those who do not understand how the cronjob works here goes a small exemeplo:
Runs from hour to hour
0 * * * * comando
Runs every hour, from 1 to 5
0 1-5 * * * comando
According to the above image, how could I create a validation for a cronjob expression?
I only need to validate the content of the time that will be executed, I do not need to validate the command that comes after the expression.
Note: I only need logic to learn regex, so any language is valid for the answer.
Starts here http://aurelio.net/regex/guia/
– MagicHat
The comma, asterisk and bar mean what?
– rray
The comma and the bar are literal characters, the asterisk is a greedy quantifier. @rray
– MagicHat
From what I understand, this is more of an algorithm than a REGEX, for example, if
1-15
you mean to say1 a 15
minutes, and0,30
0 or 30 minutes you have different sentences(0?[1-9])|(1[0-5])
,0|30
. Specify the parameters :D better– Guilherme Lautert
Put 1 full sample line to make it easy....
– MagicHat
Complementing the @Magichat tip, if you want to learn regular expressions the book from Aurelio is a good investment.
– pmargreff