Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio regular expression for finding commented blocks of code

I am beginning work on a large Visual Studio solution, and have come across areas that have large blocks of commented-out code. The blocks are usually more than 3 lines in length, and all start with // (probably Ctrl+K,C was used to comment these out). I would like to try to find out all the places these exist in my solution so our team can address them, and delete them if they are no longer needed (after all, we are using proper source-code control and can always go back in history to see the old code!).

So I am interested in commented out blocks of code that span more than 3 consecutive lines (and I don't want get a lot of false-positives for the XML documentation comments either). What regular expression can I use in Visual Studio's find dialog to look for these blocks? I tried the following, but it doesn't seem to work:

//[^/].*\n[:Wh]*//[^/].*\n[:Wh]*//[^/]

I'm not trying to do a find-and-replace - just find them and we'll look at them before deleting the code if it's no longer needed.

Thanks!

like image 786
David McClelland Avatar asked Oct 14 '09 13:10

David McClelland


2 Answers

The other answers didn't work for me in Visual Studio 2012 (not sure if anything's changed). The following did:

(^[ \t]*//[^/].*\r?\n){3,}
like image 157
avesse Avatar answered Oct 29 '22 00:10

avesse


Try this one:

[:Wh]//[^/].*\n[:Wh]*//[^/].*\n[:Wh]*//[^/].*\n

Works for me.

like image 25
Philippe Avatar answered Oct 29 '22 01:10

Philippe