[issue17257] re module shows unexpected non-greedy behavior when using groups

2013-02-20 Thread Hendrik Lemelson

New submission from Hendrik Lemelson:

When using the Python 2.7.3 re module, it shows a strange behavior upon the use 
of quantifiers together with groups:

>>> re.search('(a*)', 'ct').groups()
('',)
>>> re.search('(a+)', 'ct').groups()
('',)
>>> re.search('(a{0,5})', 'ct').groups()
('',)
>>> re.search('(a{1,5})', 'ct').groups()
('',)

Whenever a quantifier is used that allows also zero occurrences, the quantifier 
loses its greedy behavior. This in my eyes is a defect in the re module. In the 
following there is another example with nested groups where the quantifier for 
the outer group even prevents the inner groups to match:

>>> re.search('(a(b*)a)', 'caabbaat').groups()
('aa', '')
>>> re.search('(a(b+)a)', 'caabbaat').groups()
('abba', 'bb')
>>> re.search('(a(b*)a){0,1}', 'caabbaat').groups()
(None, None)
>>> re.search('(a(b+)a){0,1}', 'caabbaat').groups()
(None, None)

It would be great if you could manage to fix this.
Thank you in advance.

Regards
Hendrik Lemelson

--
components: Regular Expressions
messages: 182535
nosy: Hendrik.Lemelson, ezio.melotti, mrabarnett, pitrou
priority: normal
severity: normal
status: open
title: re module shows unexpected non-greedy behavior when using groups
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue17257>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17257] re module shows unexpected non-greedy behavior when using groups

2013-02-21 Thread Hendrik Lemelson

Hendrik Lemelson added the comment:

Thank you for clarifying this. While it still not seems really intuitive to me 
I can handle the behavior.

To summarize: It is not possible with re to have an optional ({0,1}) group that 
contains further subgroups, because re considers (0,0) to already fulfill the 
constraints for the outer group?

--
resolution:  -> invalid
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue17257>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com