Date/Time
Date with Month Name Regex
Many documents write dates in a readable day-month-year style, such as 12 Jan 2026 or 31 December 1999. This pattern accepts a day from 1 to 31, with or without a leading zero, followed by an English month name in full or short form and a four-digit year, with an optional comma before the year. It captures the day and year, while the month text sits in between. It is useful for parsing invoices, letters and press releases. The honest limit is that it does not accept ordinals like 12th or month-first forms like Jan 12, 2026.
Pattern (JavaScript)
/^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$/Starts at the start of the line/string, then a group (the character "0", optionally (zero or one time), then one of the characters 1-9 OR one of the characters 12, then a digit OR the character "3", then one of the characters 01), then a space, then (the text "Jan", then (the text "uary"), optionally (zero or one time) OR the text "Feb", then (the text "ruary"), optionally (zero or one time) OR the text "Mar", then (the text "ch"), optionally (zero or one time) OR the text "Apr", then (the text "il"), optionally (zero or one time) OR the text "May" OR the text "Jun", then the character "e", optionally (zero or one time) OR the text "Jul", then the character "y", optionally (zero or one time) OR the text "Aug", then (the text "ust"), optionally (zero or one time) OR the text "Sep", then (the character "t" OR the text "tember"), optionally (zero or one time) OR the text "Oct", then (the text "ober"), optionally (zero or one time) OR the text "Nov", then (the text "ember"), optionally (zero or one time) OR the text "Dec", then (the text "ember"), optionally (zero or one time)), then the character ",", optionally (zero or one time), then a space, then a group (a digit, exactly 4 times), then the end of the line/string.
Limit: Checks the format only; it does not check calendar validity like 31 February or leap years.
Examples
Matches
- ✓ 12 Jan 2026
- ✓ 1 March 2025
- ✓ 31 December, 1999
Does not match
- ✗ 12 Janx 2026
- ✗ 32 Jan 2026
- ✗ Jan 12 2026
Try it
0 matches (JavaScript engine)
12 Jan 2026
1 March 2025
31 December, 1999
12 Janx 2026
32 Jan 2026
Jan 12 2026Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$/g;
const text = "12 Jan 2026";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$')
text = '12 Jan 2026'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$/';
$text = '12 Jan 2026';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$");
String text = "12 Jan 2026";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$`)
text := "12 Jan 2026"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$");
var text = "12 Jan 2026";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$").unwrap();
let text = "12 Jan 2026";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$/
text = '12 Jan 2026'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- How do I accept ordinals like 12th?
- Add (?:st|nd|rd|th)? straight after the day group. That accepts 1st, 2nd, 3rd and 12th, although it will also accept odd forms like 1th.
- How do I match month-first dates like Jan 12, 2026?
- Write a second pattern with the month group first, then the day and an optional comma before the year. Keeping the two orders separate makes each pattern easier to read.
- Is the month name case-sensitive?
- Yes, as written it expects a capital first letter. Add the i flag if your text may contain jan or JAN.
Related patterns
- Month Name\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b
- Date DD/MM/YYYY^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$
- ISO 8601 Date (YYYY-MM-DD)^([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
- US Date MM/DD/YYYY^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$