简体   繁体   English

在visual studio 2012中查找所有注释行

[英]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 他们使用//,他们不使用/ ** /如何使用正则表达式在visual studio 2012中找到所有这样的注释行

In that find it should not find any xml comments with /// 在那找到它不应该找到任何xml评论///

Simply try as 试试吧

(?<!/)//.*(?!/)
  • (?<!/) Negative Lookbehind - To check the // doesn't contains / as a preceding character (?<!/) Negative Lookbehind - 检查//不包含/作为前一个字符
  • //.* Matches any character including // except newline //.*匹配包括//除换行之外的任何字符
  • (?!/) Negative Lookahead - To check the // doesn't contains / as a next character (?!/)否定前瞻 - 检查//不包含/作为下一个字符

use this patten 用这个模式

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

(?<!/) means it can not be / before // (?<!/)表示它不能/之前//

(?!/) means it can not be / after // (?!/)表示它不能/之后//

Try this expression (?<!\\/)\\/\\/[^\\/].* 试试这个表达式(?<!\\/)\\/\\/[^\\/].*

and for .NET as someone mentioned: (?<!/)//[^/].* 对于有人提到的.NET : (?<!/)//[^/].*

Try this regex: 试试这个正则表达式:

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

First group should give you the commented line. 第一组应该给你注释行。

Demo 演示

This should cover most spacing cases and work in all VS versions. 这应涵盖大多数间距情况,并适用于所有VS版本。 I believe look-behinds are only supported in VS2013. 我相信只有VS2013支持后视镜。

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

表达式应该是这样的:

//.*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM