Regular Expression

Keith Dart kdart at kdart.com
Wed Dec 15 07:51:05 CET 2004


Michael McGarry wrote:
> Hi,
> 
> I am horrible with Regular Expressions, can anyone recommend a book on it?
> 
> Also I am trying to parse the following string to extract the number 
> after load average.
> 
> ".... load average: 0.04, 0.02, 0.01"
> 
> how can I extract this number with RE or otherwise?

This particular example might be parsed more quickly and easily just by 
chopping it up:

s = ".... load average: 0.04, 0.02, 0.01"
[left, right] = s.split(":")
[av1, av2, av3] = map(float, map(str.strip, right.split(",")))



-- 
                            \/ \/
                            (O O)
-- --------------------oOOo~(_)~oOOo----------------------------------------
Keith Dart <kdart at kdart.com>
vcard: <http://www.kdart.com/~kdart/kdart.vcf>
public key: ID: F3D288E4       URL: <http://www.kdart.com/~kdart/public.key>
============================================================================



More information about the Python-list mailing list