Issue 814253: Grouprefs in lookbehind assertions (original) (raw)

Created on 2003-09-29 03:31 by glchapman, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sre_parse.patch glchapman,2003-11-02 15:31
Messages (11)
msg18411 - (view) Author: Greg Chapman (glchapman) Date: 2003-09-29 03:31
I was trying to get a pattern like this to work: pat = re.compile(r'(?<=(...)\1)abc') pat.match('jkljklabc', 6) Unfortunately, that doesn't work. The problem is that sre_parse.Subpattern.getwidth() ignores GROUPREFs when calculating the width, so the subpattern in the assertion is deemed to have length of 3 (I was hoping that sre could detect that the group 1 had a fixed length, so the reference to it would also have a fixed length). I've since discovered that both Perl and PerlRE cannot handle the above pattern, but they both generate exceptions indicating that the assertion has a variable length pattern. I think it would be a good idea if sre generated an exception as well (rather than silently ignoring GROUPREFs).
msg18412 - (view) Author: Greg Chapman (glchapman) Date: 2003-11-02 15:31
Logged In: YES user_id=86307 Attached is a patch which gives GROUPREFs an arbitrary variable width, so that they raise an exception if used in a lookbehind assertion. Obviously, it would be better if GROUPREFs returned the length of the group to which they refer, but I don't see any obvious way for getwidth() to get that information (perhaps I missed something?).
msg83234 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2009-03-06 03:11
As part of issue #2636 group references now work in lookbehinds. However, your example: (?<=(...)\1)abc will fail but: (?<=\1(...))abc will succeed. Why? Well, in lookbehinds it searches backwards. In the first regex it sees the group reference before the capture, whereas in the second it sees the group reference after the capture. (Hope that's clear! :-))
msg114290 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-18 22:39
I've deliberately changed the stage to patch review and the version to 3.2 to highlight the fact that a lot of work will be needed to get the new regex engine into the standard library. Feel free to change these as is seen fit.
msg190042 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2013-05-26 00:41
Can this be closed as a result of work done via #2636 or must it remain open?
msg190044 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2013-05-26 00:57
Issue #2636 resulted in the regex module, which supports variable-length look-behinds. I don't know how much work it would take even to put a limited fixed-length look-behind fix for this into the re module, so I'm afraid the issue must remain open.
msg229918 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-10-24 12:05
The patch for fixes this issue too.
msg230824 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-07 19:49
New changeset fac649bf2d10 by Serhiy Storchaka in branch '2.7': Issues #814253, #9179: Group references and conditional group references now https://hg.python.org/cpython/rev/fac649bf2d10 New changeset 9fcf4008b626 by Serhiy Storchaka in branch '3.4': Issues #814253, #9179: Group references and conditional group references now https://hg.python.org/cpython/rev/9fcf4008b626 New changeset 60fccf0aad83 by Serhiy Storchaka in branch 'default': Issues #814253, #9179: Group references and conditional group references now https://hg.python.org/cpython/rev/60fccf0aad83
msg230827 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-07 20:37
New changeset 0e2c7d774df3 by Serhiy Storchaka in branch '2.7': Silence the failure of test_pyclbr after adding a property in sre_parse https://hg.python.org/cpython/rev/0e2c7d774df3 New changeset 246c9570a757 by Serhiy Storchaka in branch '3.4': Silence the failure of test_pyclbr after adding a property in sre_parse https://hg.python.org/cpython/rev/246c9570a757 New changeset b2c17681404f by Serhiy Storchaka in branch 'default': Silence the failure of test_pyclbr after adding a property in sre_parse https://hg.python.org/cpython/rev/b2c17681404f
msg230829 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-07 21:29
Now group references to groups with fixed width are supported in lookbehind assertions.
msg236357 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-02-21 10:12
New changeset b78195af96f5 by Serhiy Storchaka in branch 'default': Issues #814253, #9179: Group references and conditional group references now https://hg.python.org/cpython/rev/b78195af96f5 New changeset 5387095b8675 by Serhiy Storchaka in branch '2.7': Issues #814253, #9179: Warnings now are raised when group references and https://hg.python.org/cpython/rev/5387095b8675 New changeset e295ad9be16d by Serhiy Storchaka in branch '3.4': Issues #814253, #9179: Warnings now are raised when group references and https://hg.python.org/cpython/rev/e295ad9be16d
History
Date User Action Args
2022-04-10 16:11:27 admin set github: 39322
2015-02-21 10:12:03 python-dev set messages: +
2014-11-07 21:29:40 serhiy.storchaka set status: open -> closedversions: + Python 2.7, Python 3.4, Python 3.5, - Python 3.2messages: + assignee: effbot -> serhiy.storchakaresolution: fixedstage: patch review -> resolved
2014-11-07 20:37:06 python-dev set messages: +
2014-11-07 19:49:37 python-dev set nosy: + python-devmessages: +
2014-10-24 12:05:32 serhiy.storchaka set superseder: Lookback with group references incorrect (two issues?)messages: + nosy: + serhiy.storchaka
2014-02-03 17:13:53 BreamoreBoy set nosy: - BreamoreBoy
2013-05-26 00:57:26 mrabarnett set messages: +
2013-05-26 00:42:00 BreamoreBoy set messages: +
2010-08-18 22:39:59 BreamoreBoy set versions: + Python 3.2, - Python 2.7nosy: + BreamoreBoymessages: + stage: patch review
2010-08-03 19:37:32 terry.reedy set versions: + Python 2.7, - Python 2.5, Python 2.4, Python 2.3
2009-03-06 03:11:25 mrabarnett set nosy: + mrabarnettmessages: +
2007-09-11 06:25:46 effbot set type: behaviorversions: + Python 2.5, Python 2.4
2003-09-29 03:31:55 glchapman create