Date/Time
Month Name Regex
Human-written dates often spell out the month, in full or as a three-letter abbreviation. This pattern finds any English month name or standard short form, including the four-letter Sept, case-insensitively and only as a whole word, so it does not fire inside words like marching, janitor or octopus. It is useful for parsing emails, invoices, meeting notes and scraped event listings, or for highlighting dates in a text editor. The honest limit is that May is also an ordinary English word and a name, so sentences such as you may go will produce a match.
Pattern (JavaScript)
/\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b/iMatches a word boundary, 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 a word boundary.
Examples
Matches
- ✓ due in March
- ✓ Sept 2026
- ✓ dec
Does not match
- ✗ Marching band
- ✗ the janitor
- ✗ octopus
Try it
3 matches (JavaScript engine)
due in March Sept 2026 dec Marching band the janitor octopus
Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b/gi;
const text = "due in March";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b', re.I)
text = 'due in March'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b/i';
$text = 'due in March';
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("\\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\\b", Pattern.CASE_INSENSITIVE);
String text = "due in March";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b`)
text := "due in March"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b", RegexOptions.IgnoreCase);
var text = "due in March";
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"(?i)\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b").unwrap();
let text = "due in March";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b/i
text = 'due in March'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- How do I avoid matching the word may?
- Require context, for example a nearby day number or year, such as \bMay [0-9]{1,2}\b. Alternatively drop the i flag so only the capitalised form matches.
- Does this support other languages?
- No, it only covers English month names. Build a separate alternation for each language you need, keeping them in a lookup table rather than one huge pattern.
- How do I convert the matched name to a month number?
- Take the first three letters of the match, lowercase them and look them up in a map from jan to 1 through dec to 12. This works for both full and short forms.
Related patterns
- Date with Month Name^(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})$
- Year 1900 to 2099\b(?:19|20)[0-9]{2}\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])$