Regexp and multiple groups (with repeats)
Neil Cerutti
neilc at norwich.edu
Fri Nov 20 10:52:30 EST 2009
On 2009-11-20, mk <mrkafk at gmail.com> wrote:
> 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')
You'll have to do something else, for example:
>>> s = re.compile(r'(?:[a-zA-Z]:)')
>>> n = re.compile(r'[\\/]\w+')
>>> m = s.match('c:/tmp/spam/eggs')
>>> n.findall(m.string[m.end():])
['/tmp', '/spam', '/eggs']
--
Neil Cerutti
More information about the Python-list
mailing list