#NEWLINE# def shebang_matches( text , regex ) : #NEWLINE# #INDENT# "\n    Check if the given regular expression matches the last part of the\n    shebang if one exists.\n\n        >>> from pygments.util import shebang_matches\n        >>> shebang_matches('#!/usr/bin/env python', r'python(2\\.\\d)?')\n        True\n        >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\\.\\d)?')\n        True\n        >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\\.\\d)?')\n        False\n        >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\\.\\d)?')\n        False\n        >>> shebang_matches('#!/usr/bin/startsomethingwith python',\n        ...                 r'python(2\\.\\d)?')\n        True\n\n    It also checks for common windows executable file extensions::\n\n        >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\\.\\d)?')\n        True\n\n    Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does\n    the same as ``'perl -e'``)\n\n    Note that this method automatically searches the whole string (eg:\n    the regular expression is wrapped in ``'^$'``)\n    " #NEWLINE# index = text . find ( '\n' ) #NEWLINE# if ( first_line >= 0 ) : #NEWLINE# #INDENT# first_line = text [ : index ] . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# first_line = text . lower ( ) #NEWLINE# #UNINDENT# if first_line . startswith ( '#!' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# found = [ x for x in split_path_re . split ( first_line [ 2 : ] . strip ( ) ) if ( x and ( not x . startswith ( '-' ) ) ) ] [ ( - 1 ) ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# regex = re . compile ( ( '^%s(\\.(exe|cmd|bat|bin))?$' % regex ) , re . IGNORECASE ) #NEWLINE# if ( regex . search ( found ) is not None ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# return False