使用正则内部的逻辑短路匹配之一举多得
如果只匹配一个注释的话:
要判断它在不在字符串内:向前统计引号个数???
是不是正则的一部分:只存在 reg =/\//
这种情况,但(?>!)的兼容性貌似不是很好
只需要给出字符串、注释、正则表达式
基本构成条件就不会出现上面两个问题
regexp = /str|regexp|lineannotaion|blockannotation|tampstring/g
let tmp='', str = `
${
tmp+'\`'+"${
}"+
`${
tmp}`+ /*A*/
(tmp={'a':/(?<!x`)/g}["a"]) //B
}'c' \" <d> & // e /*f*/`, // g
reg = /(?<!\\)\/(?![^\/\*])[\s\S]+?(?<!\\)\//g;
//*/ h
str; reg = /c/g, str = ``
/*/ j
k //KK
//*/
str = "\"http://'xxxx'\/\"";
str = `.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ')${
`l`+str}`
str = '\
\' //n"`\
' /* // */
匹配任意字符
/[\s\S]/g
/[^]/g
匹配单行注释
/\/\/.*/g
匹配多行注释
/\/\*[^]*?\*\//g
匹配字符串
/('|"|`)[^]*?(?<!\\)\1/g
/''|``|""|('|"|`)[^]*?[^\\]\1/g
/''|""|('|")[^]*?[^\\]\1|`(?:\\[\s\S]|\${
(?:[^{
}<