例如,
'POINT (-109.42948819496439 44.5177967942721)'
Run Code Online (Sandbox Code Playgroud)
如何从前面的字符串中提取lat和long值?
我试过了:
coords.substring(7,14) + ' ' + coords.substring(15,22)
Run Code Online (Sandbox Code Playgroud)
但我认为我不能依赖它
// Robust matching of two space-separated floats within parentheses:
let point = 'POINT (-109.42948819496439 44.5177967942721)';
let [, lat, long] = point.match(/\(([+-]?[0-9.]+) ([+-]?[0-9.]+)\)/);
console.log(lat, long);Run Code Online (Sandbox Code Playgroud)
注意:RegExp仅与提供的测试用例保证一样健壮.抛出TypeErrorif模式不匹配.
| 归档时间: |
|
| 查看次数: |
46 次 |
| 最近记录: |