DD
DevDash

Regex for Cron Expression (5-field)

Regex Pattern

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

Standard 5-field cron expression (min hour dom month dow)

Quick Answer

The regex pattern for cron expression (5-field) is `^(?:[0-9*,/-]+\s+){4}[0-9*,/-]+$`. Standard 5-field cron expression (min hour dom month dow). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
* * * * *✓ Matches
0 9 * * 1-5✓ Matches
*/5 * * * *✓ Matches
0 0 1,15 * *✓ Matches
* * * *✗ No match
* * * * * *✗ No match
invalid✗ No match
60 * * * *✗ No match

Code Examples

javascript

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

python

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

ruby

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

php

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

java

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

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.