I am attempting to parse the following string
content = "ACC=OFF,Latitude = 01 15 30.20S Longitude = 036 47 10.83E,Speed = 0.00Km/h,Odometer = 36.477Km,2014-05-05,05:54"
As follows:
print re.findall(r'([\w\.-]+)=([\w\.-]+)', content)
The output is:
[('ACC', 'OFF')]
But the expected output should be:
[('ACC', 'OFF'),('Latitude','01 15 30.20S'),('Longitude','036 47 10.83E'),('Speed','0.00Km/h'),('Odometer','36.477Km').......]
Any help would be much appreciated
Remember whitespace and /:
In [13]: re.findall(r'([\w\.-]+)\s*=\s*([\w\.\s/-]+)', content)
Out[13]:
[('ACC', 'OFF'),
('Latitude', '01 15 30.20S Longitude '),
('Speed', '0.00Km/h'),
('Odometer', '36.477Km')]
As you can see, Longitude is not recognized because it is taken to be a part of the Latitude value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With