def shebang_matches(text, regex):
 index = text.find('\n')
 if (index >= 0):
  first_line = text[:index].lower()
 else:
  first_line = text.lower()
 if first_line.startswith('#!'):
  try:
   found = [x for x in split_path_re.split(first_line[2:].strip()) if (x and (not x.startswith('-')))][(-1)]
  except IndexError:
   return False
  regex = re.compile(('^%s(\\.(exe|cmd|bat|bin))?$' % regex), re.IGNORECASE)
  if (regex.search(found) is not None):
   return True
 return False

def shebang_matches ( text , regex ) : index = text . find ( '\n' ) if ( index >= 0 ) : first_line = text [ : index ] . lower ( ) else : first_line = text . lower ( ) if first_line . startswith ( '#!' ) : try : found = [ x for x in split_path_re . split ( first_line [ 2 : ] . strip ( ) ) if ( x and ( not x . startswith ( '-' ) ) ) ] [ ( - 1 ) ] except IndexError : return False regex = re . compile ( ( '^%s(\\.(exe|cmd|bat|bin))?$' % regex ) , re . IGNORECASE ) if ( regex . search ( found ) is not None ) : return True return False
check if the given regular expression matches the last part of the shebang if one exists .