This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
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
process
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 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg157265 - (view) Author: py.user (py.user) * Date: 2012-04-01 08:11
http://docs.python.org/py3k/library/re.html
"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()
'abc'
>>> re.match(r'(?<=\b)abc', 'abc').group()
'abc'
>>> re.match(r'(?<=\A)abc', 'abc').group()
'abc'
>>> re.match(r'(?<=\A)abc', 'abc', re.DEBUG).group()
assert -1 
  at at_beginning_string 
literal 97 
literal 98 
literal 99 
'abc'
>>>


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.
http://hg.python.org/cpython/rev/7c262962b681

New changeset 7f35da912739 by Ezio Melotti in branch '3.2':
#14461: fix wording.
http://hg.python.org/cpython/rev/7f35da912739

New changeset d68b4885fc0f by Ezio Melotti in branch 'default':
#14461: merge with 3.2.
http://hg.python.org/cpython/rev/d68b4885fc0f
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.
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58666
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