Notepad ++中的正则表达式以获取资源键

时间:2021-07-23 08:37:45

标签: regex notepad++

我需要帮助想出一个用于清理 aspx 页面条目的正则表达式。

....
Line 24: <asp:Button ID="id1" runat="server" meta:resourceKey="ButtonTxt"/>
Line 35: <asp:Label ID="id2" runat="server" meta:resourceKey="Name"></asp:Label>
Line 47: <asp:Label ID="id3" runat="server" meta:resourcekey="Other_Name"></asp:Label>
....

如何编写正则表达式以仅提取 meta:resourceKey="ButtonTxt"meta:resourceKey="Name"meta:resourcekey="Other_Name" 等。基本上我只需要提取 meta:resourcekey="xxxx" 字符串。

我试过 .*?(meta:.*?").* 但这只能到第一个 "

1 个答案:

答案 0 :(得分:0)

您使用 ? 限定符将 * 限定符置于 " 非贪婪(或“懒惰”)之前。这意味着它将尽可能少地与给定的模式匹配。这就是为什么这个量词只匹配到第一个 "。其余部分包含在您的匹配组后面的 .* 中。

如果删除 ?,则 * 量词匹配贪婪(这是默认行为)。贪婪的量词将尽可能匹配,在您的情况下是第二个 "

您可以在这里看到不同之处:https://regex101.com/r/IgA15K/1

还有一些关于这个概念的文档:https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#greedy-and-lazy-quantifiers

相关问题