[Tutor] re question
john.ertl at fnmoc.navy.mil
Thu Mar 24 19:10:16 CET 2005
I have a string that has a bunch of numbers with the units attached to them.
I want to strip off the units. I am using a regular expression and sub to
do this. This works great for almost all of the cases.
These are the type of lines:
SigWind: 857hPa, , 21.0C, 20.1C, 210 @ 9kts
SigWind: 850hPa±, , , , 205 @ 11kts
Std Lvl: 850hPa, 1503m, 16.8C, 15.7C, 205 @ 11kts
I am using the following cleanstring = re.compile( '(hPa|hPa\xb1|m|C|kts)'
). And then the cleanstring.sub("",line). I have tried using numerous \ to
escape the \xb1.
I also tried replacing all non numeric characters that are part of a
number-character string but I could not make that work. The idea was replace
all non-number characters in a "word" that is made up of numbers followed by
I then split the line at the commas so in the current thinking I need the
commas for the split. How do I deal with the hPa±? When I print it out it
looks like it is a hexadecimal escape character (\xb1) but I am note sure
how to deal with this.
More information about the Tutor