python regular expression help
Qilong Ren
qilong_ren at yahoo.com
Wed Apr 11 22:14:01 EDT 2007
Hi,
Thanks for reply. That actually is not what I want. Strings I am dealing with may look like this:
s = 'a = 4.5 b = 'h' 'd' c = 4.5 3.5'
What I want is
a = 4.5
b = 'h' 'd'
c = 4.5 3.5
----- Original Message ----
From: liupeng <liupeng at 18mail.cn>
To: python-list at python.org
Sent: Wednesday, April 11, 2007 6:41:30 PM
Subject: Re: python regular expression help
pattern = re.compile(r'\w+\s*=\s*[0-9]*.[0-9]*\s*')
lists = pattern.findall(s)
print lists
['a=4 ', 'b=3.4 ', 'c=4.5']
On Wed, Apr 11, 2007 at 06:10:07PM -0700, Qilong Ren wrote:
> Hi, everyone,
>
> I am extracting some information from a given string using python RE. The
> string is ,for example,
> s = 'a = 4 b =3.4 5.4 c = 4.5'
> What I want is :
> a = 4
> b = 3.4 5.4
> c = 4.5
> Right now I use :
> pattern = re.compile(r'\w+\s*=\s*.*?\s+')
> lists = pattern.findall(s)
> It works for the string like 'a = 4 b = 3.4 c = 4.5', but does not work with
> strings like 'a=4 b=3.4 5.4 c = 4.5'
>
> Any suggestion?
>
> Thanks,Qilong
>
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Don't get soaked. Take a quick peak at the forecast
> with theYahoo! Search weather shortcut.
> --
> http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070411/3041ca2d/attachment.html>
More information about the Python-list
mailing list