如何匹配js中的单行注释?
我有一段字符串
var str = `
//test 1
console.log('123'); //test 2
console.log('http://a.com')`;
str.match(/\/\/[^\n]*/g);
想匹配出//test 1 //test 2这种注释,而且排除掉http://a.com,该如何写正则呢
网友回答:
浮囡 2018-10-9 6:38 回复:
已被采纳
/^\/\/\S*/g
/(?<!\:)\/\/\S*/g 排除掉 //前有:的情况
/(?<!\:)\/\/[^\n]*/g //匹配更完全