我想匹配$${}$$中的内容str比较复杂,如下,我想找出所有双$$花括号的内容,并放进一个数组,该如何做?[{"field_id":"DM0002","field":"$${gender}$$","weight":"0.5","data_type":"1","condition_scores":[{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","type":"word"},{"option":"gte","value":"$${userName}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"50"},{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""},{"option":"lt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"80"}]}]JSON如下[{"field_id":"DM0002","field":"$${gender}$$","weight":"0.5","data_type":"1","condition_scores":[{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","type":"word"},{"option":"gte","value":"$${userName}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"50"},{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""},{"option":"lt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"80"}]}]自己尝试使用/^\$\$\{(\w{1,10})\}\$\$$/.exec('$${4555}$$222$${4555555788}$$')匹配不成功,求解答
2 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
varstr='[{"field_id":"DM0002","field":"$${gender}$$","weight":"0.5","data_type":"1","condition_scores":[{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","type":"word"},{"option":"gte","value":"$${userName}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"50"},{"condition":{"type":"and","options":[{"option":"gt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""},{"option":"lt","value":"$${gender}$$","data_type":"","type":"word","field_id":"","filed":""}]},"score":"80"}]}]'varreg=/\$\$\{(\w+)\}\$\$/g;varresult=str.match(reg).map(item=>item.replace(reg,'$1'));console.log(result);ORvarresult=[];varr=''do{r=reg.exec(str);r&&result.push(r[1]);}while(r!==null)
添加回答
举报
0/150
提交
取消