var o ={
myName:'Willy Leung',
sex:'Male'}var str ='<p>${myName}</p><p>${sex}</p>';/*var getMatchedStrs = function (str) {
var reg = /\$\{(.+?)\}/
var reg_g = /\$\{(.+?)\}/g
var result = str.match(reg_g)
var list = []
for (var i = 0; i < result.length; i++) {
var item = result[i]
list.push(item.match(reg)[1])
}
return list
}*/// 推荐vargetExecStrs=function(str, value){var reg =/\$\{(.+?)\}/gvar list =[]var r =nullvar res = str
do{
r = reg.exec(str)if(r) list.push(r[1])}while(r)for(var item of list){var reg =newRegExp('[\$][\{]'+ item +'[\}]','gm')if(value[item]) res = res.replace(reg, value[item])}return res
}
console.log(getExecStrs(str, o));//<p>Willy Leung</p><p>Male</p>
const str ='My name is ${name}, she is not ${name}.'const r = str.replaceAll('${name}','Willy Leung')
console.log(r)