Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Java 8

"
((?:\d{1,2}-)?\d{1,2})(?:st|nd|rd|th)?[ ./-](feb|\d{1,2})(?:[ ./-](\d{2,4}))?|(feb|\d{1,2})[ ./-]((?:\d{1,2}-)?\d{1,2})(?:st|nd|rd|th)?(?:[ ./-](\d{2,4}))?
"
igm

Description

A proof of concept regex that captures dates and date ranges with a variety of separators.

Works with both DMY and MDY, and if one is not needed, it can be easily deleted from the regex.

The full variety of months needs to be implemented by the programmer themselves since developing it in regex101 is unfeasible and would clutter the regex.

Submitted by Matey Krastev - 2 years ago