我想从 KML 文件中提取一些纬度和经度值,如下所示:
<coordinates>0.197118,48.003719,0.000000</coordinates>
// ...
<coordinates>
0.197120,48.003719,0.000000
0.197060,48.003792,0.000000
0.198390,48.004059,0.000000
</coordinates>
// ...
<coordinates>0.196763,48.003162,0.000000</coordinates>
所以你可以在文本中看到坐标的格式是:
(space*)longitude,latitude,altitude\n // or
(space*)<coordinates>longitude,latitude,altitude</coordinates>\n
所以要赶上纬度,没关系,我匹配:
@".*?,(.*?),.*?$" // matching index 1
对于经度,我使用了模式:
@" * (<coordinates>)? (.*?),(.*?),(.*?)$" // matching index 2
我尝试了很多东西,包括最后一种模式,但我总是得到匹配:
"<coordinates>0.197118",
"0.197120"
"0.197060"
"0.198390"
"<coordinates>0.196763"
你明白了:我不想要<coordinates>
。
有什么问题@" * (<coordinates>)? (.*?),(.*?),(.*?)$"
?
谢谢。