[Python-bugs-list] [ python-Bugs-833106 ] Match delimited by ^ and $ doesn't catch everything

SourceForge.net noreply at sourceforge.net
Thu Oct 30 10:08:26 EST 2003


Bugs item #833106, was opened at 2003-10-30 15:08
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=833106&group_id=5470

Category: Regular Expressions
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Kochanski (gpk)
Assigned to: Fredrik Lundh (effbot)
Summary: Match delimited by ^ and $ doesn't catch everything

Initial Comment:
import re
 
_sfp = re.compile(r'^(?:(.*?)([XY][0-9]))*(.*?)$')
 
print _sfp.search('testX1Y2').groups()
print _sfp.match('testX1Y2').groups()
print _sfp.search('testY1X2again').groups()
print _sfp.search('testX1').groups()
print _sfp.search('Y2').groups()

Yields

('', 'Y2', '')
('', 'Y2', '')
('', 'X2', 'again')
('test', 'X1', '')
('', 'Y2', '')


Note that in the first three outputs, the string 'test'
doesn't appear in any group.

Note also that 'X1' doesn't appear in any group in
the first two outputs.

The RE is delimited by ^ and $, so it should match
everything or fail.   It doesn't fail.
All the elements of the RE are in parentheses, so
everything should fall into one group or another.
Thus, all the text should show up in one group
or another.

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

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



More information about the Python-bugs-list mailing list