【发布时间】:2015-02-16 11:59:57
【问题描述】:
是否有正则表达式来匹配任何行注释,但避免字符串中的 cmets?
我需要// 之后的一行中的所有内容(包括//)
例如:
//Comment (match!)
bla bla bla bla //Comment (match!)
this string "foo // foo" (don't match because it's inside "")
【问题讨论】:
-
我不认为你可以做这个纯正则表达式
-
你可以,正如我的回答所展示的那样。我原本打算证明语法是context-free 而不是regular,但我最终创建了a finite automation,它可以识别语法。