On Jul 22, 7:45 pm, "scriptlear...@gmail.com"
<scriptlear...@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(),

p = re.compile('#a=([^;]*);b=([^;]*);c=([^;]*);')
m = p.match(line)
if m:
    print m.group(1),m.group(2),m.group(3),

Note that "=*;" in your regex will match
zero or more "=" characters -- probably not
what you intended.

"[^;]* will match any string up to the next
";" character which will be a value (assuming
you don't have or care about embedded whitespace.)

You might also want to consider using a r'...'
string for the regex, which will make including
backslash characters easier if you need them
at some future time.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to