正则表达式查找未注释的 println
有人可以分享一个正则表达式来找到java代码中所有非双斜杠注释的 println 吗?
示例:(
System.out.println("MATCH") /*this line match*/
// System.out.println("DOESN'T MATCH") /*this line doesn't match*/
我使用这个正则表达式来抛出 Eclipse 搜索对话框)
Can someone share a regex that find all not double-slashed commented println in java code?
Example:
System.out.println("MATCH") /*this line match*/
// System.out.println("DOESN'T MATCH") /*this line doesn't match*/
(I'm using this regex into throw eclipse searching dialog)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,正如我已经提到的,正则表达式不是正确的工具,所以如果您最终使用我的建议,请务必备份您的源!
以下正则表达式匹配其中包含
System.out.print
、without
//
或/*
的单行> 在它之前(在同一行!)。或者简单地:
然后可以替换为:
来评论它。
再次强调:多行注释会出错,正如 Kobi 提到的,像
/* // */ System.out.print...
这样的东西仅举出此正则表达式将出现的许多情况中的两个绊倒。还要考虑这一行:
你不想最终得到:
Okay, as I already mentioned, regex is not the right tool, so if you end up using my suggestion, be sure to backup your source!
The following regex matches a single line that has
System.out.print
in it,without
//
or/*
before it (in that same line!).or simply:
which can then be replaced with:
to comment it.
Again: this will go wrong with multi line comments, and as Kobi mentioned, stuff like
/* // */ System.out.print...
to name just two of the many cases this regex will trip over.Also consider the line:
you don't want to end up with:
你也许可以做一些简单的事情,比如:
You could probably just do something simple like: