亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

正則表達式匹配獲取指定內容

正則表達式匹配獲取指定內容

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}`);

    });

}


查看完整回答
反對 回復 2018-11-26
  • 1 回答
  • 0 關注
  • 688 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號