Expanding the pattern for more readability:
(
(?<month>
jan(uary)?
| feb(ruary)?
| mar(ch)?
| apr(il)?
| may
| jun(e)?
| jul(y)?
| aug(ust)?
| sep(t?|tember)?
| oct(ober)?
| nov(ember)?
| dec(ember)?
)
(
(\\s+)?
(?<date>\\d+)?
(st|nd|rd|th)
)?
(\\s+)?
,?
(\\s+)?
(?<year>(20)\\d\\d)?
)
The spaces before the year can match even when the year does not. Additionally, the date suffix can match even when the date does not.
Cleaning and fixing the pattern I got this:
\\b
(?<month>
jan(uary)?
| feb(ruary)?
| mar(ch)?
| apr(il)?
| may
| jun(e)?
| jul(y)?
| aug(ust)?
| sep(t|tember)?
| oct(ober)?
| nov(ember)?
| dec(ember)?
)
(
\\s*
(?<date>\\d+)
(st|nd|rd|th)?
)?
(
\\s*
,?
\\s*
(?<year>(19|20)\\d\\d)
)?
\\b
I removed the outer group, since you get that as group 0 anyway. The t?
in sep(t?|tember)?
was changed to just t
. All the (\\s+)?
was changed to the equivalent \\s*
. I moved the ?
from (?<date>\\d+)?
to (st|nd|rd|th)
. I wrapped the year in a group, and moved the ?
from (?<year>20\\d\\d)
to that. I added word-boundaries (\\b
), so that it won't start or end in the middle of a word.
As one line:
\\b(?<month>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(t|tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s*(?<date>\\d+)(st|nd|rd|th)?)?(\\s*,?\\s*(?<year>(19|20)\\d\\d))?\\b
Combining it with your second pattern:
\\b
(
(?<month1>
jan(uary)?
| feb(ruary)?
| mar(ch)?
| apr(il)?
| may
| jun(e)?
| jul(y)?
| aug(ust)?
| sep(t|tember)?
| oct(ober)?
| nov(ember)?
| dec(ember)?
)
(
\\s*
(?<date1>\\d+)
(st|nd|rd|th)?
)?
|
(?<date2>\\d+)
(st|nd|rd|th)?
\\s*
(?<month2>
jan(uary)?
| feb(ruary)?
| mar(ch)?
| apr(il)?
| may
| jun(e)?
| jul(y)?
| aug(ust)?
| sep(t|tember)?
| oct(ober)?
| nov(ember)?
| dec(ember)?
)
)
(
\\s*
,?
\\s*
(?<year>(19|20)\\d\\d)
)?
\\b
As one line:
\\b((?<month1>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(t|tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s*(?<date1>\\d+)(st|nd|rd|th)?)?|(?<date2>\\d+)(st|nd|rd|th)?\\s*(?<month2>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(t|tember)?|oct(ober)?|nov(ember)?|dec(ember)?))(\\s*,?\\s*(?<year>(19|20)\\d\\d))?\\b