regex for month

Regex for Month

Regular expressions or regex are patterns used to match character combinations in strings. A regex for month would match a string that contains a month name or abbreviation.

Regex Pattern:


    (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
  

The above regex pattern matches any month name or abbreviation in a case-sensitive manner. It uses the pipe symbol '|' to separate the different options for the months.

Other Regex Patterns:

  • Full month name: (January|February|March|April|May|June|July|August|September|October|November|December)
  • 3-letter abbreviation: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
  • 2-digit month number: (0[1-9]|1[0-2])

The first pattern matches the full month name, while the second pattern matches the 3-letter abbreviation. The third pattern matches the 2-digit month number, including leading zeros.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe