node正则表达式如何多行匹配
发布于 1个月前 作者 lzxue 171 次浏览 来自 问答

var str="var lonlatInfo={\nM_3105666:{key:’1’,lonlat:’118.789890,32.047731’,jobids:[58781024,58780931,57147594,57147571,57147555,57147544]},\nM_3 48 0497:{key:’2’,lonlat:’118.789666,32.032052’,jobids:[66302053,65842688,65947231,65940611]},\nM_2538076:{key:’3’,lonlat:’118.767236,32.026676’ ,jo b ids:[6 4064711,63063090]},\nM_3266712:{key:’4’,lonlat:’118.784536,32.053148’,jobids:[66301632]},\nM_3452861:{key:’5’,lonlat:’118.80371 3,32.04 61 78\ ‘,j obids64637131]},\nM_210583:{key:’6’,lonlat:’118.855483,31.956999’,jobids:[58650772]},\nM_3506957:{key:’7’,lonlat:’118.784536,3 2.053148’,jobids:[663 01037]},\nM_2746684:{key:’8’,lonlat:’118.786830,32.049026’,jobids:[56442808]},\nM_3231093:{key:’9’,lonlat:’118.761176,32.077 413’,jobids:[66300960]},\n M_3261184:{key:’10’,lonlat:’118.793211,32.050940’,jobids:[60621412]},\nM_3520580:{key:’11’,lonlat:’118.796926,32.05109 4’,jobids:[66048832]},\nM_282 9117:{key:’12’,lonlat:’118.783693,32.033515’,jobids:[66300513,66300437,66300406,66300349,66300264,66300231,663 00161,66300092,66300041,6630002 0,66299695,66300624]},\nM_2363040:{key:’13’,lonlat:’118.809487,32.063525’,jobids:[65302351]},\nM_255484:{key:’ 14’,lonlat:’118.787007,32.068968’,jobi ds:[56119844]},\nM_3432803:{key:’15’,lonlat:’118.778091,32.073811’,jobids:[64229358,64231968]},\nM_2151142: {key:’16’,lonlat:’118.790208,32.044504’ ,jobids:[66041413,66205514,56009987,53641403]},\nM_3417134:{key:’17’,lonlat:’118.759941,32.077681’,jobids:[ 66300329]},\nM_2997649:{key:’18’,lonlat:’ 118.804774,32.063531’,jobids:[66185583,66220685,66300209]},\nM_3028119:{key:’19’,lonlat:’118.791320,3 2.041203’,jobids:[66300227]},\nM_2915155:{key: '20’,lonlat:’118.761270,32.077580’,jobids:[62826439,62641921]},\nM_2735582:{key:’21’,lonlat:’118.78 6697,32.047274’,jobids:[62716255,63577223,61118 098]}};34668"

字符串如上面所示我要获取的是 lonlatInf={}里面的所有值 我写的正则表达式为:

      var reg=/var lonlatInfo=\{\s*\}\}/m;//匹配不到该怎么写?
2 回复
var reg = /var lonlatInfo=\{([\s\S]*)\}/m;

这个用substr也能做,数一下字符个数,头尾一掐就成了。。。

不用加m var reg = /var lonlatInfo={([\s\S]*)}/; var ret = reg.exec(str); if(ret.length > 1) alert(ret[1])

回到顶部