2015-10-20 41 views
-6

我有這個字符串正則表達式來獲得之間的子串{}

dojo.io.script.jsonp_dojoIoScript1._jsonpCallback({"messages":[],"routes":{"fieldAliases":{"ObjectID":"ObjectID","Name":"Name","FirstStopID":"FirstStopID","LastStopID":"LastStopID","StopCount":"StopCount","Total_TravelTime":"Total_TravelTime","Total_Kilometers":"Total_Kilometers","Total_Miles":"Total_Miles","Shape_Length":"Shape_Length"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102100,"latestWkid":3857},"features":[{"attributes":{"ObjectID":1,"Name":"Location 1 - Location 2","FirstStopID":1,"LastStopID":2,"StopCount":2,"Total_TravelTime":0.44978725961372451,"Total_Kilometers":0.11520726003715911,"Total_Miles":0.07158647252368612,"Shape_Length":140.31608185601101},"geometry":{"paths":[[[-13046166.1984,4036530.1599000022],[-13046165.647399999,4036389.8448999971]]]}}]}});

,我想正則表達式來得到這個

{"messages":[],"routes":{"fieldAliases":{"ObjectID":"ObjectID","Name":"Name","FirstStopID":"FirstStopID","LastStopID":"LastStopID","StopCount":"StopCount","Total_TravelTime":"Total_TravelTime","Total_Kilometers":"Total_Kilometers","Total_Miles":"Total_Miles","Shape_Length":"Shape_Length"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102100,"latestWkid":3857},"features":[{"attributes":{"ObjectID":1,"Name":"Location 1 - Location 2","FirstStopID":1,"LastStopID":2,"StopCount":2,"Total_TravelTime":0.44978725961372451,"Total_Kilometers":0.11520726003715911,"Total_Miles":0.07158647252368612,"Shape_Length":140.31608185601101},"geometry":{"paths":[[[-13046166.1984,4036530.1599000022],[-13046165.647399999,4036389.8448999971]]]}}]}}

換句話說,我想在{...}之間的子串

任何想法?

謝謝!

+2

你不應該使用得到JSON文件信息的正則表達式 – DreadfulWeather

+0

你有什麼嘗試到目前爲止? – binarymason

+0

爲什麼不執行'dojo.io.script.jsonp_dojoIoScript1._jsonpCallback()'函數,然後彈出奇怪的值你不想要的?你忘了正則表達式。正則表達式並不總是答案.. 1/10確定..但不是9/10。 ''dojo'應該在第二個想法中爲你執行那個函數,你應該有一個javascript Object do:'var i = {'a':'a','b':'b'};刪除我['a']; console.log(i);'和你保存自己SOOOO很麻煩!! –

回答

1

嘗試了這一點:

/\{[0-9A-Za-z\":\[\]\{\},\._\s-]*\}/ 

測試可以在這裏完成:http://refiddle.com/2jq3

編輯:錯過\}前的最後/

+1

我認爲這比較好:http://refiddle.com/refiddles/5626da0c75622d5088050000 - 我仍然不同意這種使用正則表達式解析它的方法。 –

+0

這很有用,謝謝! –

相關問題