Regex to match month name followed by year
Is it possible to use a regex to match "February 2009", for example?
Along the lines of
\b(?:Jan(?:uary)?|Feb(?:ruary)?|...|Dec(?:ember)?) (?:19[7-9]\d|2\d{3})(?=\D|$)
that's
\b # a word boundary (?: # non-capturing group Jan(?:uary)? # Jan(uary) |Feb(?:ruary)? # |... # and so on |Dec(?:ember)? # Dec(ember) ) # end group # a space (?: # non-capturing group 19[7-9]\d|2\d{3} # 1970-2999 ) # end group (?=\D|$) # followed by: anything but a digit or the end of string
I had to work on this to match a few fringe examples, but I ended up using
(\b\d{1,2}\D{0,3})?\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)\D?(\d{1,2}\D?)?\D?((19[7-9]\d|20\d{2})|\d{2})
to capture dates with word months in them