Cron Expression (Quartz/Spring, 6-Field)
Validate 6-field Quartz/Spring cron expressions including the seconds field at the front.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
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).
Python (re) code
import re
pattern = re.compile(r"^(\*|([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])$")
input_text = "0 0 9 * * 1"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(\*|([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])$`)
input := `0 0 9 * * 1`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
^(\*|([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])$Raw source: ^(\*|([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])$
How it works
Examples
Input
0 0 9 * * 1Matches
0 0 9 * * 1
Input
30 15 12 ? * 5Matches
30 15 12 ? * 5
Input
0 9 * * 1No match
—Common use cases
- •Spring `@Scheduled` validation
- •Quartz scheduler config forms
- •Java enterprise job-runner UIs
- •Java/Kotlin DSL builders for schedules
Related patterns
Cron Expression
ValidationValidate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.
BCP 47 Language Tag
ValidationValidate BCP 47 language tags like `en`, `en-US`, `zh-Hant-TW`, or `pt-BR`.
Email Address Validation
ValidationMatch and validate email addresses in the standard user@domain.tld format.
Email Domain Part (After @)
ValidationValidate just the domain portion of an email address — the bit after the @.