Find all comments in visual studio 2012

My project was developed by many people. Many developers commented on some of their codes.

I have a lot of codes like

//ServiceResult serviceResult = null; //JavaScriptSerializer serializer = null; //ErrorContract errorResponse = null; 

They use //, they do not use / ** / How can I find all such commented-out line in visual studio 2012 using regular expression

In this search he should not find any xml comments with ///

+4
source share
6 answers

use this patten

 (?<!/)//(?!/) 

(?<!/) means that it cannot be / before //

(?!/) means that it cannot be / after //

+2
source

Just try how

 (?<!/)//.*(?!/) 
  • (?<!/) Negative Lookbehind - for checking // not contained / as a preceding character
  • //.* Matches any character, including // , except for a newline
  • (?!/) Negative Lookahead - to check // not contained / as the next character
+3
source

Try this expression (?<!\/)\/\/[^\/].*

and for .NET , as someone said: (?<!/)//[^/].*

+1
source

Try this regex:

 ^\s*(?<!/)(//(?!/).+)$ 

The first group should provide you with a commented line.

Demo

+1
source

This should cover most cases of gaps and work in all versions of VS. I believe backtracks are only supported in VS2013.

 ^(?:\s|\t)*?//(?!/\s*<).+$ 
+1
source

The expression should be like this:

 //.* 
-3
source

All Articles