从URL中拉出Lat和Long

时间:2014-10-09 06:36:48

标签: javascript jquery

我的网址看起来像这样:

var results['GoogleLink'] = http://maps.google.com/?q=33.6745%2C%20-117.167%20(%22Menifee+Valley+Farmers+Market%22) 

从此,我想:

33.6745%2C%20-117.167%20

我试过这个(糟糕的非工作试验)

var expression = '/\/?q=\/(.*)/[1]';
var regex = new RegExp(expression);
var original = results['GoogleLink'];

如何解析此字符串并返回我想要的部分?

2 个答案:

答案 0 :(得分:2)

试试这个

var results = "http://maps.google.com/?q=33.6745%2C%20-117.167%20(%22Menifee+Valley+Farmers+Market%22)" ;
results=results.substring(results.indexOf("=")+1, results.lastIndexOf("("));
alert(results);

答案 1 :(得分:1)

试一试:

var expression = '/\/?q=\/(.*)/[1]';
var original = results['GoogleLink'];
var result = expression.test(original);

您可以使用结果进行验证