<分区>
我正在尝试编写一个选择器,它过滤掉/删除注释 (#) 符号后的所有内容,但忽略字符串中的 # 符号(""或 '')
所以在下面的例子中只有最后一行会被过滤/删除
"#dummy comment" asd asd
' abc # dummy comment'
abc #real comment
这是我到目前为止想出的两个正则表达式选择器(我稍后会添加 s/标签):
/('|").*#.*('|")/g --> selects fake commnts
/#(?!!).+/g ---> highlights all comments, including above ones (?!! is to ignore #!/usr/bin/env perl )
我目前正在努力加入这两个评论以实现上述结果。我试过使用正向和反向查找,但似乎无法做到这一点。任何建议都将不胜感激。