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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top