In Visual Studio 2010, how do you search for text that is not within a single line comment?

半腔热情 提交于 2019-11-30 15:22:23

问题


In Visual Studio 2010, how do you search for text that is not within a single line comment? E. G. how to find "bas" in:

foo bar bas

but not in

foo bar // bas

Note that it should find the line:

foo / bar / bas

(edit) And it should not find the line:

foo // bar bas

回答1:


Okay, so I asked this question just so I could refer back to my own answer.

Visual Studio doesn't seem to have the typical look-ahead, look-behind constructs. It does have a similar zero-width negative assertion. The syntax is ~(x) which means the pattern does not match x at this point in the pattern. Using this construct, I came up with this: ^(.~(//))*bas Which works really well, but won't exclude a line where // are the first two characters on the line. A version to fix that is: ^~(//)(.~(//))*bas




回答2:


In the Visual Studio Find dialog, try using this regular expression (make sure to select Use: Regular expressions in the Find options):

~(//[.:b]*)<bas>

This should find all occurrences of the word bas which are not preceded by //.

Note that the Visual Studio regex syntax is a bit different than the conventional syntax. You can find the reference HERE.



来源:https://stackoverflow.com/questions/9022258/in-visual-studio-2010-how-do-you-search-for-text-that-is-not-within-a-single-li

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!