regex question

rusi rustompmody at
Fri Jul 29 10:53:53 EDT 2011

Can someone throw some light on this anomalous behavior?

>>> import re
>>> r ='a(b+)', 'ababbaaabbbbb')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: no such group

>>> re.findall('a(b+)', 'ababbaaabbbbb')
['b', 'bb', 'bbbbb']

So evidently group counts by number of '()'s and not by number of
matches (and this is the case whether one uses match or search). So
then whats the point of search-ing vs match-ing?

Or equivalently how to move to the groups of the next match in?

[Side note: The docstrings for this really suck:

>>> help(
Help on built-in function group:



More information about the Python-list mailing list