[Tutor] Help on RE
Japhy Bartlett
japhy at pearachute.com
Sun Jan 23 01:51:35 CET 2011
it's a bug in your regex - you want something like "-?\d+"
- japhy
On Sat, Jan 22, 2011 at 7:38 PM, tee chwee liong <tcl76 at hotmail.com> wrote:
> hi,
>
> 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?
> For eg:
>
> Platform: PC
> Tempt : 25
> TAP0 :0
> TAP1 :1
> +++++++++++++++++++++++++++++++++++++++++++++
> Port Chnl Lane EyVt EyHt
> +++++++++++++++++++++++++++++++++++++++++++++
> 0 1 1 75 55
> 0 1 2 10 35
> 0 1 3 25 35
> 0 1 4 35 25
> 0 1 5 10 -1
> +++++++++++++++++++++++++++++++++++++++++++++
> Time: 20s
>
> When i run my code, i get 1 instead of -1 in the last line. here is my code.
> pls advise. i'm using Python 2.5 and Win XP. tq
> ##code###
> import re
> file = open("C:/Python25/myscript/plot/sampledata.txt", "r")
> x1 = []
> y1 = []
> y2 = []
> for line in file:
> numbers = re.findall("\d+", line)
> print numbers
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list