【发布时间】:2019-10-14 06:54:47
【问题描述】:
如果想选择任何具有 XML 语句但其中需要缺少属性的行。所以我能够很容易地找到坏数据。
所以这个解决方案在这里有效,但在我的示例中,我没有任何新行。它没有任何空格。
正则表达式:
/^<SomeState((?!SearchedAttribute).)*$/gm
适用于:
它再也找不到它们了。
如何将所有内容都放在同一行上?
想法 #1:
/<SomeState((?!SearchedAttribute).)*/gm
已经更好了,但我不想选择条件:
测试字符串:
<SomeState><SearchedAttribute Key=Value/></SomeState>
<SomeState><SearchedAttribute Key=Value/></SomeState>
<SomeState Attr1><BadAttribute Key=Value/></SomeState>
<SomeState><SearchedAttribute Key=Value/></SomeState>
<SomeState><BadAttribute Key=Value/></SomeState>
【问题讨论】:
-
哪种风格的正则表达式?
-
您可能应该使用 XML 解析器,因为您在此处嵌套了内容。
-
XML 解析器可能会更好,但我想用正则表达式解决它。谢谢。
-
如果您将数据作为文本而不是图像提供,那就太好了!结果也可以通过 regex101.com 显示
-
在@csabinho上方找到测试字符串
标签: regex regex-lookarounds regex-negation