Description

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 is referenced in 0 repositories