fork download
  1. import re, time, datetime
  2.  
  3. text = 'this amendment of lease, made and entered as of the 10th day of august, 2016, by and between john doe and jane smith this agreement, made and entered as of May 1, 2016, between john doe and jane smith'
  4.  
  5. regex = re.compile('(?:(\d{1,2})(?:th|nd|rd).* ([a-z]{3})[a-z]*|([a-z]{3})[a-z]* (\d{1,2})),\s*(\d{4})', re.I)
  6.  
  7. for x in regex.findall(text):
  8. if x[0] == '':
  9. date = '-'.join(filter(None, x))
  10. else:
  11. date = '%s-%s-%s' % (x[1],x[0],x[4])
  12.  
  13. print(datetime.datetime.strptime(date, '%b-%d-%Y').date())
  14.  
Success #stdin #stdout 0.06s 65804KB
stdin
Standard input is empty
stdout
2016-08-10
2016-05-01