Regex for Cron Expression
Validates standard 5-field cron expressions (minute, hour, day-of-month, month, day-of-week).
Pattern
/^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$/ Live Tester
Enter a string to test
Examples
✓ * * * * *
✓ 0 12 * * 1
✓ 30 6 15 1 *
✗ * * *
✗ 60 * * * *
✗ not a cron
Pattern Breakdown
(\*|[0-5]?\d)(\/\d+)? — minute (0-59 or * with optional step)
(\*|[01]?\d|2[0-3])(\/\d+)? — hour (0-23 or *)
(\*|[0-3]?\d)(\/\d+)? — day of month (0-31 or *)
(\*|[01]?\d|1[0-2])(\/\d+)? — month (0-12 or *)
(\*|[0-7])(\/\d+)? — day of week (0-7 or *)
Code Snippets
Javascript
const regex = /^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$/;
regex.test("0 12 * * 1"); // true Python
import re
pattern = r"^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$"
bool(re.match(pattern, "0 12 * * 1")) # True Php
$pattern = '/^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$/';
preg_match($pattern, "0 12 * * 1"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for Cron Expression?▾
The regex pattern for Cron Expression is /^(\*|[0-5]?\d)(\/\d+)?(\s+(\*|[01]?\d|2[0-3])(\/\d+)?)(\s+(\*|[0-3]?\d)(\/\d+)?)(\s+(\*|[01]?\d|1[0-2])(\/\d+)?)(\s+(\*|[0-7])(\/\d+)?)$/. Validates standard 5-field cron expressions (minute, hour, day-of-month, month, day-of-week).
How do I use the Cron Expression regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Cron Expression pattern match?▾
It matches strings like * * * * *; it rejects strings like * * *. See the Examples section above for the full list of matching and non-matching cases.