[docs] [issue25517] regex howto example in "Lookahead Assertions"

Pavel report at bugs.python.org
Fri Oct 30 06:07:26 EDT 2015


New submission from Pavel:

The example advises ".*[.](?!bat$).*$" expression "to match filenames where the extension is not bat". But here is an example which passes such check:

>>> re.match("(.*)[.](?!bat$).*$", "test.a.bat")
<_sre.SRE_Match object at 0x7ff221996f30>

To my mind use of negative lookbehind expressions (not covered so far in the HOWTO) is better:

>>> re.match("(.*)[.].*(?<!.bat)$", "test.a.bat")
>>>

----------
assignee: docs at python
components: Documentation
messages: 253725
nosy: Pavel, docs at python
priority: normal
severity: normal
status: open
title: regex howto example in "Lookahead Assertions"
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25517>
_______________________________________


More information about the docs mailing list