regex: multiple matching for one string
tiefeng wu
icebergwtf at gmail.com
Thu Jul 23 11:54:01 EDT 2009
2009/7/23 scriptlearner at gmail.com <scriptlearner at gmail.com>:
> For example, I have a string "#a=valuea;b=valueb;c=valuec;", and I
> will like to take out the values (valuea, valueb, and valuec). How do
> I do that in Python? The group method will only return the matched
> part. Thanks.
>
> p = re.compile('#a=*;b=*;c=*;')
> m = p.match(line)
> if m:
> print m.group(),
> --
> http://mail.python.org/mailman/listinfo/python-list
>
maybe like this:
>>> p = re.compile(r'#?\w+=(\w+);')
>>> l = re.findall(p, '#a=valuea;b=valueb;c=valuec;')
>>> for r in l: print(r)
...
valuea
valueb
valuec
tiefeng wu
2009-07-23
More information about the Python-list
mailing list