def search_year(string):
 match = re.search(u'[^0-9]([0-9]{4})[^0-9]', string)
 if match:
  year = int(match.group(1))
  if valid_year(year):
   return (year, match.span(1))
 return (None, None)

def search_year ( string ) : match = re . search ( u'[^0-9]([0-9]{4})[^0-9]' , string ) if match : year = int ( match . group ( 1 ) ) if valid_year ( year ) : return ( year , match . span ( 1 ) ) return ( None , None )
looks for year patterns .