Message182535
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*)', 'caaaat').groups()
('',)
>>> re.search('(a+)', 'caaaat').groups()
('aaaa',)
>>> re.search('(a{0,5})', 'caaaat').groups()
('',)
>>> re.search('(a{1,5})', 'caaaat').groups()
('aaaa',)
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 |
|
Date |
User |
Action |
Args |
2013-02-20 17:55:44 | Hendrik.Lemelson | set | recipients:
+ Hendrik.Lemelson, pitrou, ezio.melotti, mrabarnett |
2013-02-20 17:55:44 | Hendrik.Lemelson | set | messageid: <1361382944.02.0.85313570363.issue17257@psf.upfronthosting.co.za> |
2013-02-20 17:55:43 | Hendrik.Lemelson | link | issue17257 messages |
2013-02-20 17:55:43 | Hendrik.Lemelson | create | |
|