[Python-bugs-list] [ python-Bugs-695688 ] Problems with non-greedy match groups
SourceForge.net
noreply@sourceforge.net
Sat, 01 Mar 2003 10:52:17 -0800
Bugs item #695688, was opened at 2003-03-01 14:52
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=695688&group_id=5470
Category: Regular Expressions
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Daniel (kamek)
Assigned to: Fredrik Lundh (effbot)
Summary: Problems with non-greedy match groups
Initial Comment:
The problem is better explained with this code:
import re
regexp = re.compile(r'^begin ((.*?)X)?(.+) end$')
print regexp.search('begin oneXtwo end').groups()
# The above one will correctly print:
# ('oneX', 'one', 'two')
print regexp.search('begin two end').groups()
# ...but the above one will print:
# (None, 'two end', 'two')
# If we change regexp's non-greedy
# .*? into .*, it works as it should:
# (None, None, 'two')
The problem lies in sre; pre correctly matches the non-
greedy version.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=695688&group_id=5470