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
| Input | Result |
|---|---|
| * * * * * | ✓ 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"
endphp
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
JavaScript Variable Name
Valid JavaScript variable/identifier name
Python Variable Name
Valid Python identifier name
CSS Class Name
Valid CSS class name (starts with letter, underscore, or hyphen)
CSS ID Selector
CSS ID selector starting with #
JSON Key
JSON object key (quoted string followed by colon)
Semantic Version (Strict)
Strict semantic versioning (MAJOR.MINOR.PATCH)