Cron Expression (Quartz/Spring, 6-Field) in JS
Validate 6-field Quartz/Spring cron expressions including the seconds field at the front.
Try it in the JS tester →Pattern
regexJS
^(\*|([0-5]?\d))\s+(\*|([0-5]?\d))\s+(\*|([01]?\d|2[0-3]))\s+(\*|([1-9]|[12]\d|3[01]))\s+(\*|([1-9]|1[0-2]))\s+(\*|\?|[0-7])$JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^(\\*|([0-5]?\\d))\\s+(\\*|([0-5]?\\d))\\s+(\\*|([01]?\\d|2[0-3]))\\s+(\\*|([1-9]|[12]\\d|3[01]))\\s+(\\*|([1-9]|1[0-2]))\\s+(\\*|\\?|[0-7])$", "");
const input = "0 0 9 * * 1";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Six fields: seconds (0–59), minutes (0–59), hours (0–23), day-of-month (1–31), month (1–12), and day-of-week (0–7, where Quartz also accepts `?` to mean "no specific value"). Each field also accepts `*` for any value. This is the Quartz/Spring scheduler format — distinct from the standard 5-field Unix cron in batch 1.
Examples
Input
0 0 9 * * 1Matches
0 0 9 * * 1
Input
30 15 12 ? * 5Matches
30 15 12 ? * 5
Input
0 9 * * 1No match
—