Ric*_*cky 19 regex visual-studio regex-negation
如何在Visual Studio搜索框中检索包含"strA"但不包含"strB"的文档的所有行?
Tim*_*ker 35
对于Visual Studio 2012(以及更新版本):
^(?!.*strB).*strA.*$
Run Code Online (Sandbox Code Playgroud)
说明:
^ # Anchor the search at the start of the line
(?!.*strB) # Make sure that strB isn't on the current line
.*strA.* # Match the entire line if it contains strA
$ # Anchor the search to the end of the line
Run Code Online (Sandbox Code Playgroud)
(?:\r\n)?
如果您还想删除回车符/换行符以及行的其余部分,则可能需要在正则表达式的末尾添加.
Ala*_*ore 18
对于Visual Studio 2010(和以前的版本):
Visual Studio搜索框有自己的,奇异的正则表达式语法版本.此表达式按要求工作:
^~(.*strB).*strA
Run Code Online (Sandbox Code Playgroud)
^
匹配一行的开头.(通常对于文本编辑器,没有"多行"选项; ^
并且$
始终在行边界处匹配.)
.
匹配除换行符之外的任何字符.(不常见的是,似乎没有"单线"或"全点"模式,让点匹配换行符.)
~(...)
是"防止匹配"构造,等同于(据我所知)(?!...)
其他响应者使用的负向前瞻().
归档时间: |
|
查看次数: |
7909 次 |
最近记录: |