Download Cheat sheet PDF 12 pages · syntax, editors, patterns, Unicode, performance, debugging
Pattern

Regex for Month name

English month name, full or abbreviated.

The Month name regex is ^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$ — copy it below, or open it in the explainer for a token-by-token breakdown.

The pattern

^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$
Try in explainer → Download cheat sheet ↓

What it matches

  • January
  • Feb
  • March
  • dec? no

What it doesn't match

  • january
  • febr
  • 13

Notes & gotchas

English month names, full or 3-letter abbreviation. Case-sensitive — add /i flag if needed. For other languages, build a similar alternation.

Code in your language

Use the explainer's Code tab to generate ready-to-paste snippets in JavaScript, Python, Java, .NET, Go, Ruby, and PHP for this pattern.

Open in explainer →

Token-by-token breakdown

Every part of the pattern, left to right:

TokenMeaning
^start of string (or line in multiline mode)
(start of a capturing group
Januaryliteral text “January”
|OR — try the alternative
Februaryliteral text “February”
|OR — try the alternative
Marchliteral text “March”
|OR — try the alternative
Aprilliteral text “April”
|OR — try the alternative
Mayliteral text “May”
|OR — try the alternative
Juneliteral text “June”
|OR — try the alternative
Julyliteral text “July”
|OR — try the alternative
Augustliteral text “August”
|OR — try the alternative
Septemberliteral text “September”
|OR — try the alternative
Octoberliteral text “October”
|OR — try the alternative
Novemberliteral text “November”
|OR — try the alternative
Decemberliteral text “December”
|OR — try the alternative
Janliteral text “Jan”
|OR — try the alternative
Febliteral text “Feb”
|OR — try the alternative
Marliteral text “Mar”
|OR — try the alternative
Aprliteral text “Apr”
|OR — try the alternative
Mayliteral text “May”
|OR — try the alternative
Junliteral text “Jun”
|OR — try the alternative
Julliteral text “Jul”
|OR — try the alternative
Augliteral text “Aug”
|OR — try the alternative
Sepliteral text “Sep”
|OR — try the alternative
Octliteral text “Oct”
|OR — try the alternative
Novliteral text “Nov”
|OR — try the alternative
Decliteral text “Dec”
)end of group
$end of string (or line in multiline mode)

About this pattern

Date and time formats vary enormously across regions and systems. The regex here validates structure only — a date like 2024-02-30 would pass format validation but isn't a real date. After regex passes, parse with your language's date library to confirm semantic validity.

Quick usage in different languages

This exact pattern — with the correct escaping and idioms for each language:

  • JavaScript: /^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/.test(value)
  • Python: re.match(r"^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$", value)
  • Java: Pattern.compile("^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$").matcher(value).matches()
  • C# / .NET: Regex.IsMatch(value, @"^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$")
  • Go: regexp.MustCompile(`^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$`).MatchString(value)
  • Ruby: /^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/.match?(value)
  • PHP: preg_match('~^(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$~', $value)

The explainer’s Code tab regenerates these for any pattern you paste, and the downloadable cheat sheet bundles the breakdown, all seven snippets, and the pitfalls below onto one printable page.

Common pitfalls

  • Anchored to the whole string. This pattern uses ^ and $, so it requires the entire input to match. To find it inside a longer text, drop the anchors and use the global (g) flag.
  • Validate beyond format. Matching the format doesn't guarantee the value is real. Confirm the month name against a source of truth (database, API, or checksum) where it matters.

Related patterns

More patterns in the Date & time category:

See also

Browse all 300 patterns in the library, or open this regex in the interactive explainer to see a token-by-token breakdown, test against custom input, and generate code in seven languages.


← Back to all patterns