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>
|