[issue13998] Lookbehind assertions go behind the start position for the match

Devin Jeanpierre report at bugs.python.org
Sun Feb 12 09:54:43 CET 2012


New submission from Devin Jeanpierre <jeanpierreda at gmail.com>:

compiled regex objects' match method offers an optional "pos" parameter described to be roughly equivalent to slicing except for how it treats the "^" operation. See http://docs.python.org/library/re.html#re.RegexObject.search

However, the behavior of lookbehind assertions also differs:

>>> re.compile("(?<=a)b").match("ab", 1)
<_sre.SRE_Match object at 0x...>
>>> re.compile("(?<=a)b").match("ab"[1:])
>>>

This alone might be a documentation bug, but the behavior is also inconsistent with the behavior of lookahead assertions, which do *not* look past the endpos:

>>> re.compile("a(?=b)").match("ab", 0, 1)
>>> re.compile("a(?=b)").match("ab")
<_sre.SRE_Match object at 0x...>
>>>

----------
components: Regular Expressions
messages: 153188
nosy: Devin Jeanpierre, ezio.melotti
priority: normal
severity: normal
status: open
title: Lookbehind assertions go behind the start position for the match
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2

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


More information about the Python-bugs-list mailing list