[Tutor] Help on RE
Steve Willoughby
steve at alchemy.com
Sun Jan 23 01:55:37 CET 2011
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.
More information about the Tutor
mailing list