正则匹配${XXX}
判断字符串${}里的内容是否是指定的数组里的
buttonArr: ["${aaa}", "${bbb}", "${identifier}"],
created() {
this.getPlaceholder('/.ota/device/inform/${aaa}/${bbb}')
},
getPlaceholder(url) {
let reg_g = /\$\{(.*?)\}/g;//(.*?)\}表示匹配任意字符到离它最近的'}'
let result = url.match(reg_g);
console.log(result)
let isFlag = true;
result.map((item) => {
let index = this.buttonArr.indexOf(item);
if (index < 0) {
isFlag = false;
}
});
console.log(isFlag)
return isFlag
},
运行结果
若${}不是指定的字符
this.getPlaceholder('/.ota/device/inform/${aaa}/${ccc}')