2014-10-09 70 views
0

我的URL看起來像這樣:拉動緯度和長從URL

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

試試這個

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); 
+0

好主意!謝謝。 – 2014-10-09 07:04:16

+0

隨時歡迎。感謝您將它標記爲答案 – 2014-10-09 07:06:13

0

嘗試:

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

可以使用結果來驗證