开发者

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!


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,}


Try this one:

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

Works for me.


Try this one on for size:

((^.*[^/])|(^)//[^/].*\n)+

Actually this works best for me so far:

(((^.*[^/])|(^)//[^/].*\n)|(^//\n))(((^.*[^/])|(^)//[^/].*\n)|
(^//\n))(((^.*[^/])|(^)//[^/].*\n)|(^//\n))(((^.*[^/])|(^)//[^/].*\n)|(^//\n))+

It is long but it only gets four or more continuous comment lines and handles blank comment lines (just // and nothing else no content).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜