Quick and easy way to remove "dead" (commented out) code

Paul Sasik picture Paul Sasik · Mar 10, 2010 · Viewed 7.6k times · Source

I'm working with an inherited code base which contains thousands of lines of commented out code. I know the previous coder meant to save all his hard work for posterity rather than simply deleting it but: I will never read it and it just gets in the way. One problem example is that when I perform text searches for certain code segments I gets dozens of "false" hits in the commented code. PITA.

Is there a quick/easy way to detect large blocks of commented out code? A clever RegEx perhaps?

I happen to be working in VB.NET at this time and comment character is a single apostrophe.

Answer

Hans Passant picture Hans Passant · Mar 10, 2010

You can use a Regular Expression search. Search for

^.*'.*$

To find a single line with a comment. You'll probably want to find at least 3 lines that start with a comment:

^.*'.*\n.*'.*\n.*'.*$

Keep the cat away from your keyboard.