def datetime_parsing(text, base_date=datetime.now()):
 matches = []
 found_array = []
 for (expression, function) in regex:
  for match in expression.finditer(text):
   matches.append((match.group(), function(match, base_date), match.span()))
 for (match, value, spans) in matches:
  subn = re.subn((('(?!<TAG[^>]*?>)' + match) + '(?![^<]*?</TAG>)'), (('<TAG>' + match) + '</TAG>'), text)
  text = subn[0]
  is_substituted = subn[1]
  if (is_substituted != 0):
   found_array.append((match, value, spans))
 return sorted(found_array, key=(lambda match: (match and match[2][0])))

def datetime_parsing ( text , base_date = datetime . now ( ) ) : matches = [ ] found_array = [ ] for ( expression , function ) in regex : for match in expression . finditer ( text ) : matches . append ( ( match . group ( ) , function ( match , base_date ) , match . span ( ) ) ) for ( match , value , spans ) in matches : subn = re . subn ( ( ( '(?!<TAG[^>]*?>)' + match ) + '(?![^<]*?</TAG>)' ) , ( ( '<TAG>' + match ) + '</TAG>' ) , text ) text = subn [ 0 ] is_substituted = subn [ 1 ] if ( is_substituted != 0 ) : found_array . append ( ( match , value , spans ) ) return sorted ( found_array , key = ( lambda match : ( match and match [ 2 ] [ 0 ] ) ) )
extract datetime objects from a string of text .