- while跟正则方法exec搭配使用可以将捕获的分组全部获取到
- 比如: a/{projectPath}/{itemPath}/{path},这三个path都可以在while中res输出
const path = a/{projectPath}/{itemPath}/{path}
const reg = /{(.*?)}/g;
let res = null;
const pathFormListArr = [];
let i = 0;
while ((res = reg.exec(path))) {
console.log('res', res);
if (pathFormList[i]) {
pathFormListArr.push({
parameterExample: pathFormList[i].parameterExample,
note: pathFormList[i].note,
key: new Date().getTime() + res[1] + Math.random(),
name: res[1],
});
} else {
pathFormListArr.push({
key: new Date().getTime() + res[1] + Math.random(),
name: res[1],
parameterExample: '',
note: '',
});
i++;
}
}