我在变量a中存储了一个类似这样的LatLng(41.3371, 19.81717)字符串,但是我只需要数字41.3371来做一些进一步的计算。你知道我该怎么提取号码吗?
发布于 2012-08-15 19:38:08
使用正则表达式,您可以执行/^LatLng\((\d+\.\d+), (\d+\.\d+)\)$/。
使用javascript的:
console.log('LatLng(41.3371, 19.81717)'.match(/^LatLng\((\d+\.\d+), (\d+\.\d+)\)$/)[1]);发布于 2012-08-15 19:39:20
使用正则表达式,如
<div id="res"></div>
<script type="text/javascript">
var res = document.getElementById('res'),
re = /\((\d+\.\d+),\s*(\d+\.\d+)\)/,
str = 'LatLng(41.3371, 19.81717)',
m = str.match(re);
res.innerHTML = 'x = ' + m[1] + ' and y = ' + m[2];
</script>
https://stackoverflow.com/questions/11968555
复制相似问题