[Python-bugs-list] [ python-Bugs-405358 ] Python2.0 re module: greedy regexp bug

nobody nobody@sourceforge.net
Thu, 01 Mar 2001 21:35:12 -0800


Bugs #405358, was updated on 2001-03-01 20:37
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=405358&group_id=5470

Category: Regular Expressions
Group: None
Status: Open
Priority: 5
Submitted By: Nobody/Anonymous
Assigned to: Fredrik Lundh
Summary: Python2.0 re module: greedy regexp bug

Initial Comment:
Python-2.0 fails to correctly handle cases when greedy
and non-greedy regular expressions are present in the
same pattern. In some cases non-greedy are more
aggressive than greedy searches!!

Here is an example:

TESTB-BED system: San Solaris 2.6
Python 2.0 (#1, Dec  9 2000, 12:35:40) 
[GCC 2.95.2 19991024 (release)] on sunos5

Please, run the following code to see the bug:

import re
str='first_XXXX_last'
#                   \1  \2    \3
mo = re.search(r'^(.*?)(X*)(.*?)$', str)
# above, the groups \1 and \3 are NON-greedy regexp
# while group \2 is greedy.
# Unfortunately Python-2.0 demonstrates buggy behavior
# here:
print "BUGGY result:", mo.groups()
print "should be   : ('first_', 'XXXX', '_last')"
#EOF

When I run the code above it prints the following:

BUGGY result: ('', '', 'first_XXXX_last')
should be   : ('first_', 'XXXX', '_last')
>>> 

Thanks,
--Leo  <slonika@yahoo.com>


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

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