Kuttan Sujith
Kuttan Sujith

Reputation: 7979

Find all commented line in visual studio 2012

My project is developed by many people. Many of the developers have commented few of their codes

I have a lot of codes like

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

They use // ,they don't use /**/ How can I find all such commented line in visual studio 2012 using regular expression

In that find it should not find any xml comments with ///

Upvotes: 4

Views: 118

Answers (6)

Narendrasingh Sisodia
Narendrasingh Sisodia

Reputation: 21437

Simply try as

(?<!/)//.*(?!/)
  • (?<!/) Negative Lookbehind - To check the // doesn't contains / as a preceding character
  • //.* Matches any character including // except newline
  • (?!/) Negative Lookahead - To check the // doesn't contains / as a next character

Upvotes: 3

Pierluc SS
Pierluc SS

Reputation: 3176

This should cover most spacing cases and work in all VS versions. I believe look-behinds are only supported in VS2013.

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

Upvotes: 1

NeverHopeless
NeverHopeless

Reputation: 11233

Try this regex:

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

First group should give you the commented line.

Demo

Upvotes: 1

maraaaaaaaa
maraaaaaaaa

Reputation: 8163

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

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

Upvotes: 1

Sky Fang
Sky Fang

Reputation: 1101

use this patten

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

(?<!/) means it can not be / before //

(?!/) means it can not be / after //

Upvotes: 2

Ced
Ced

Reputation: 1301

The expression should be like this:

//.*

Upvotes: -3

Related Questions