正则表达式以获取{}之间的子字符串

时间:2015-10-20 23:44:52

标签: json regex

我是这个字符串

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]]]}}]}}

换句话说,我想要{...}

之间的子串

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个:

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

可以在此处完成测试:http://refiddle.com/2jq3

修改:在最终\}之前错过/