有一个字符串var str = '//@(test/js/index.js); //@(tass/js/inde.js); //@(tab/jsx/ind.jsx); 11230120 ;// var a = 22';';我用 var reg = /(\/\/\@\()(\S*?)(\))/g ;结果是这样的有没有一个正则匹配的规则;能获取到这样的结果['test/js/index.js','tass/js/inde.js','tab/jsx/ind.jsx]
1 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
/(?:@\()([^)]*)/g
测试地址
const regex = /(?:@\()([^)]*)/g;
const str = `//@(test/js/index.js); //@(tass/js/inde.js); //@(tab/jsx/ind.jsx); 11230120 ;// var a = 22';`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
添加回答
举报
0/150
提交
取消