Exclude comments when searching in Visual Studio

前端 未结 3 1792
無奈伤痛
無奈伤痛 2020-12-14 05:39

Is there a way to perform searches (Find / Find in Files) in visual studio that will exclude matches in comments? While sometimes it is useful, other times it is the opposi

相关标签:
3条回答
  • 2020-12-14 06:15

    Here's the regex that works for me for newer versions of Visual Studio:

    ^(?![ \t]*//).*your_search_term
    

    Note that the syntax changed as of VS 2012:

    Visual Studio 2012 uses .NET Framework regular expressions to find and replace text. In Visual Studio 2010 and earlier versions, Visual Studio used custom regular expression syntax in the Find and Replace windows.

    Reference: https://msdn.microsoft.com/en-us/library/vstudio/2k3te2cs(v=vs.110).aspx

    0 讨论(0)
  • 2020-12-14 06:32

    you could try the regex as below:

    ^~(:b*//).*your_search_term
    

    Short explanation:

    • ^ from beginning of line
    • ~( NOT the following
    • :b* any number of white spaces, followed by
    • // the comment start
    • ) end of NOT
    • .* any character may appear before
    • your_search_term your search term :-)

    saw this at another post.

    0 讨论(0)
  • 2020-12-14 06:40

    I don't believe it's an option in VS. You could try regular expressions, but those are limited by how creative you can be. It seems like it would be not entirely difficult to search for lines not beginning with // using a regex.

    0 讨论(0)
提交回复
热议问题