test_string = \'\'\'dated as of October 17, 2012 when we went caroling, dated as of December 21, 2011 when we ate bananas\'\'\'
import re
import calendar
months_f
You are very close!
Try:
import re
import calendar
test_string = '''dated as of October 17, 2012 when we went caroling, dated as of December 21, 2011 when we ate bananas'''
test_pattern = re.compile('|'.join(r'(?:\b%s\s+\d{1,2},\s+\d{4})' % month
for month in calendar.month_name[1:]))
print test_pattern.findall(test_string)
# ['October 17, 2012', 'December 21, 2011']
Other comments:
,?
at the end of your regex. It really does not validate a date any more that the first part of the regex.December 21,\n2011