Regexp and multiple groups (with repeats)

mk mrkafk at
Fri Nov 20 13:03:04 CET 2009


 >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+')


Obviously, I would like to capture all groups:
('/tmp', '/spam', '/eggs')

But it seems that re captures only the last group. Is there any way to 
capture all groups with repeat following it, i.e. (...)+ or (...)* ?

Even better would be:

('tmp', 'spam', 'eggs')

Yes, I know about re.split:

 >>> re.split( r'(?:\w:)?[/\\]', r'c:/tmp/spam\\eggs/' )
['', 'tmp', 'spam', '', 'eggs', '']

My interest is more general in this case: how to capture many groups 
with a repeat?


More information about the Python-list mailing list