code: def shebang_matches(text, regex):
      r"""Check if the given regular expression matches the last part of the
      shebang if one exists.
  
          >>> from pygments.util import shebang_matches
          >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?')
          True
          >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
          True
          >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
          False
          >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
          False
          >>> shebang_matches('#!/usr/bin/startsomethingwith python',
          ...                 r'python(2\.\d)?')
          True
  
      It also checks for common windows executable file extensions::
  
          >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')
          True
  
      Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does
      the same as ``'perl -e'``)
  
      Note that this method automatically searches the whole string (eg:
      the regular expression is wrapped in ``'^$'``)
      """
      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(
              r"^%s(\.(exe|cmd|bat|bin))?$" % regex, re.IGNORECASE
          )
          if regex.search(found) is not None:
              return True
      return False
  
imports: import re
  from io import TextIOWrapper
label_desc: Use image node_id 7 for calling a global function with example usage: shebang_matches(text, regex) and returns: False, True, False