regex: multiple matching for one string

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Jul 23 09:23:27 EDT 2009


scriptlearner at gmail.com wrote:
> 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(),

IMHO a regex for this is overkill, a combination of string methods such 
as split and find should suffice.

Regards.




More information about the Python-list mailing list