所以我從一個JavaScript文件中讀取一個字符串,將有:未註釋的正則表達式匹配線
...
require('some/path/to/file.less');
...
// require('some/path/to/file.less');
...
我使用這個REG-EX:
requireRegExp = /require(\ +)?\((\ +)?['"](.+)?['"](\ +)?\)\;?/g
爲了趕上所有這些線。但是,我需要篩選出那些被評論的人。
所以,當我運行
while(match = requireRegExp.exec(str)){
...
}
我只會如果你想只匹配那些require
使用下面得到的匹配與需要啓動註釋掉線...
'STR = str.replace(/ \/\/[^ \ r \ n]的* /克, '');' – Deadooshka
不知道這是你需要的,但'regequireRegExp =/^ require。+/g'爲我工作。 – Alex