正则表达式搜索匹配一个词但不匹配另一个词 [英] Regular Expression Searching Matching One Word but Not Another

查看:72
本文介绍了正则表达式搜索匹配一个词但不匹配另一个词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<ReportExport ID="export1" runat="server" AlertNoTests="false" PDFPageOrientation="Portrait"
            HideExcel="true" OnPDFClicked="CreatePDF" AllowPDFOptions="true" HideBulkPDFOptions="false"
            HideOrientation="true" HidePaperSize="true" MaxReportsAtOnce="250" HideTextExport="true" />

我正在尝试使用 Visual Studio 的使用正则表达式的查找功能在未设置 HideTextExport 属性的整个解决方案中查找 ReportExport.这只会在给定页面的标记中定义一次.

I'm trying to use Visual Studio's find feature using regular expressions to find ReportExport in my entire solution where the HideTextExport property is not being set. This is only ever defined in the markup once on a given page.

关于如何找到 ReportExport 存在位置的任何想法...但文本中不存在 HideTextExport?

Any ideas on how I would find where ReportExport exists... but HideTextExport does not exist in the text?

提前致谢!

推荐答案

这对我有用:

\<ReportExport(:Wh+~(HideTextExport):w=:q)+:Wh*/\>

:Wh+ 匹配属性名称前的空格,:w 匹配名称,但只有在 ~(HideTextExport) 确认之后名称不是HideTextExport".:q 匹配属性的值(假设值总是被引用).<> 必须被转义,否则 VS Find 会将它们视为单词边界.

:Wh+ matches the whitespace preceding the attribute name and :w matches the name, but only after ~(HideTextExport) confirms that the name is not "HideTextExport". :q matches the attribute's value (assuming values are always quoted). < and > have to be escaped or VS Find will treat them as word boundaries.

这实际上与 .NET 正则表达式相同,

This is effectively the same as the .NET regex,

<ReportExport(?:\s+(?!HideTextExport)[A-Za-z]+="[^"]+")+\s*/>

这篇关于正则表达式搜索匹配一个词但不匹配另一个词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆