Let's say that I have a string that looks like this:
my_date = February 4 - March 23, 2015
I want to create a regex that will extract both month names and the year, so I set it up like this:
date_regex = r"^(?:(Jan(?:uary)?|Feb(?:ruary)|Marc?h?|Apr[il1]?[I1l]?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:tober)?|Nov(?:ember)?|Dec(?:ember)?)\s+\d?\d(?:\s+-\s+)?){2},\s+(20[01]\d)"
I thought I was being clever by enclosing the whole regex to match the month and day in a non-matching group and using {2}
to say there should be two of them, but unfortunately the groups that I get from this are ("March", "2015")
. It seems like it's not capturing the first match of "February".
Where am I going wrong? Is it my regex, or is this just not possible?
This question seems related and seems to imply that what I'm trying to do isn't possible without the regex
module.
Thanks