regex to find an uncommented println
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)
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!).
(?m)^((?!//|/\*).)*System\.out\.print.*
or simply:
(?m)^[ \t]*System\.out\.print.*
which can then be replaced with:
//$0
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:
System.out.println("..."); /*
comments
*/
you don't want to end up with:
//System.out.println("..."); /*
comments
*/
You could probably just do something simple like:
^[ \t]*[^/][^/].*println.*
精彩评论