问题:
const str = 'aaa{{.bbbb}}ccc{{.ddd}}eeee';
const reg = /(?<=\{\{\.)(.+?)(?=\}\})/g;
const matchs = str.match(reg);
console.log(matchs); // ['bbbb', 'ddd']
上面代码,在ios中失效,提示
原因:
ios中不支持 零宽断言
- ?=pattern(前面是什么)
- ?!pattern(前面不是)
- ?<=pattern(后面是什么)
- ?<!pattern(后面不是什么)
解决方案:
const str = 'aaa{{.bbbb}}ccc{{.ddd}}eeee';
const reg = /{{\.(.*?)}}/g;
const matchs = str.match(reg); // ["{{.bbbb}}", "{{.ddd}}"]
matchs.map(item => {
return item.replace(/{|}|\./g, '');
});
// 或者通过循环matchs进行其他业务操作