[Python-bugs-list] [ python-Bugs-725106 ] SRE bug with capturing groups in alternatives in repeats

SourceForge.net noreply@sourceforge.net
Mon, 21 Apr 2003 10:16:52 -0700


Bugs item #725106, was opened at 2003-04-21 09:16
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=725106&group_id=5470

Category: Regular Expressions
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Chapman (glchapman)
Assigned to: Fredrik Lundh (effbot)
Summary: SRE bug with capturing groups in alternatives in repeats

Initial Comment:
SRE does not always correctly handle groups in 
alternatives in repeats.  For example:

>>> re.match('((a)|b)*', 'abc').groups()
('b', '')

Group 2 should obviously never be an empty string.  As I 
understand it, the rule for groups inside a repeat is that 
they should have the last value they matched during the 
iterations of the repeat (or None if they never match), so 
in the above case Group 2 should be 'a'.  To fix this, it 
appears that (when inside a repeat) the BRANCH 
opcode must call mark_save before trying an alternative 
and then call mark_restore if the alternative fails.  The 
attached patch does this.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=725106&group_id=5470