字符串中取得双$花括号之中的内容

我想匹配
$${}$$
中的内容
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}$$')
匹配不成功,求解答
白衣染霜花
浏览 526回答 2
2回答

一只名叫tom的猫

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)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript