[Tutor] Help on RE
tee chwee liong
tcl76 at hotmail.com
Sun Jan 23 02:01:26 CET 2011
thanks for making me understand more on re. re is a confusing topic as i'm starting on python.
> Date: Sat, 22 Jan 2011 16:55:37 -0800
> From: steve at alchemy.com
> To: tcl76 at hotmail.com
> CC: tutor at python.org
> Subject: Re: [Tutor] Help on RE
>
> On Sun, Jan 23, 2011 at 12:38:10AM +0000, tee chwee liong wrote:
> > i have a set of data and using re to extract it into array. however i only get positive value, how to extract the whole value including the -ve sign?
> > numbers = re.findall("\d+", line)
>
> The \d matches a digit character. \d+ matches one or more digit characters.
> Nothing in your regex matches a sign character. You might want something like
> [-+]\d+
> which would require either a - or + followed by digits. If you want the sign
> to be optional, maybe this would work:
> [-+]?\d+
>
>
>
>
> --
> Steve Willoughby | Using billion-dollar satellites
> steve at alchemy.com | to hunt for Tupperware.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110123/d6f03d41/attachment.html>
More information about the Tutor
mailing list