DD
DevDash

Regex for Cron Expression (6-field Quartz)

Regex Pattern

^(?:[0-9*,/-]+\s+){5}[0-9*,/?L#-]+$

6-field Quartz/Spring cron expression with seconds

Quick Answer

The regex pattern for cron expression (6-field quartz) is `^(?:[0-9*,/-]+\s+){5}[0-9*,/?L#-]+$`. 6-field Quartz/Spring cron expression with seconds. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
0 0 12 * * ?✓ Matches
*/5 * * * * *✓ Matches
0 0 0 1 1 *✓ Matches
* * * * *✗ No match
invalid cron✗ No match
* * * *✗ No match

Code Examples

javascript

const regex = /^(?:[0-9*,\/-]+\s+){5}[0-9*,\/?L#-]+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^(?:[0-9*,/-]+\s+){5}[0-9*,/?L#-]+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^(?:[0-9*,/-]+\s+){5}[0-9*,/?L#-]+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^(?:[0-9*,\/-]+\s+){5}[0-9*,\/?L#-]+$/', $value)) {
    echo "valid";
}

java

String pattern = "^(?:[0-9*,/-]+\\s+){5}[0-9*,/?L#-]+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.