HUH函數
2018-10-10 13:14:34
有一個字符串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
提交
取消