Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 943
Paul Sasik Avatar asked Mar 10 '10 22:03

Paul Sasik


2 Answers

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.

like image 176
Hans Passant Avatar answered Oct 06 '22 18:10

Hans Passant


(^\s*//.*\n)^10

Find 10 concurrent commented out lines of the // style.

Commented out tests:

\s*//\s*\[Test\].*\n
like image 33
Ben Aston Avatar answered Oct 06 '22 17:10

Ben Aston