Regexp and multiple groups (with repeats)

M

mk

Hello,
>>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+')
>>> r.search(r'c:/tmp/spam/eggs').groups()
('/eggs',)

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?

Regards,
mk
 
N

Neil Cerutti

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top