Title: In re's positive lookbehind assertion documentation match() cannot match
Type: enhancement Stage: resolved
Components: Documentation, Regular Expressions Versions: Python 3.2, Python 3.3, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: docs@python, ezio.melotti, mrabarnett, py.user, python-dev
Priority: normal Keywords:

Created on 2012-04-01 08:12 by py.user, last changed 2012-04-29 04:40 by ezio.melotti. This issue is now closed.

Messages (3)
msg157265 - (view) Author: py.user (py.user) * Date: 2012-04-01 08:11
"Note that patterns which start with positive lookbehind assertions will never match at the beginning of the string being searched; you will most likely want to use the search() function rather than the match() function:"

>>> re.match(r'(?<=^)abc', 'abc').group()
>>> re.match(r'(?<=\b)abc', 'abc').group()
>>> re.match(r'(?<=\A)abc', 'abc').group()
>>> re.match(r'(?<=\A)abc', 'abc', re.DEBUG).group()
assert -1 
  at at_beginning_string 
literal 97 
literal 98 
literal 99 

in some cases match() can match
msg159571 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-29 04:35
New changeset 7c262962b681 by Ezio Melotti in branch '2.7':
#14461: fix wording.

New changeset 7f35da912739 by Ezio Melotti in branch '3.2':
#14461: fix wording.

New changeset d68b4885fc0f by Ezio Melotti in branch 'default':
#14461: merge with 3.2.
msg159572 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-04-29 04:40
Technically you are correct, however using zero-width classes inside a lookbehind doesn't make much sense, because the result would be equivalent even without lookbehind.
I replaced 'never' with 'not', because usually it will not match, except in these corner cases that can IMHO be ignored.
Date User Action Args
2012-04-29 04:40:16ezio.melottisetstatus: open -> closed

assignee: docs@python -> ezio.melotti
versions: + Python 2.7, Python 3.3
messages: + msg159572
type: enhancement
resolution: fixed
stage: resolved
2012-04-29 04:35:38python-devsetnosy: + python-dev
messages: + msg159571
2012-04-01 08:12:00py.usercreate