Thursday, September 10, 2009

Cleanup dirty code using the power of regular expressions

In eclipse search for all irrelevant comments and clean them up:
/\*\s(\r\n.*\r\n)+(\s)+\*.*(@see)*.*(\r\n)+(\s)+\*/
or
For finding all comments blank use >> (?m:)/\*\*(\r\n)+(\s)+\* @[^/]*/
Note: m tells eclipse to search multi line.

Eg:
/*
  *
   * @see ...
   */

The above pattern can be cleaned up very easily with pattern above.



1 comment:

Anonymous said...

Multi line remove comments with text in it:

(?m:)/\*\*(\r\n.*\*.*)+