Mun*_*niu 2 python regex parsing
我试图解析以下字符串
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"
Run Code Online (Sandbox Code Playgroud)
如下:
print re.findall(r'([\w\.-]+)=([\w\.-]+)', content)
Run Code Online (Sandbox Code Playgroud)
输出是:
[('ACC', 'OFF')]
Run Code Online (Sandbox Code Playgroud)
但预期的输出应该是:
[('ACC', 'OFF'),('Latitude','01 15 30.20S'),('Longitude','036 47 10.83E'),('Speed','0.00Km/h'),('Odometer','36.477Km').......]
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激
小智 5
记住空白和/:
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')]
Run Code Online (Sandbox Code Playgroud)
如您所见,Longitude未被识别,因为它被视为Latitude价值的一部分.
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |