regex: multiple matching for one string
Nick Dumas
drakonik at gmail.com
Thu Jul 23 11:29:01 EDT 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Agreed. Two string.split()s, first at the semi-colon and then at the
equal sign, will yield you your value, without having to fool around
with regexes.
On 7/23/2009 9:23 AM, Mark Lawrence wrote:
> 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.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkpogb0ACgkQLMI5fndAv9jtOwCgj3+YOLfKGvAdyCMOhh4NGgfy
x5YAn1ydhUYxGlvC4Z4WlWKaa1gwviSh
=jnp1
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list