正则表达式的帮助:当嵌套ASP.NET评估和演示找到HTML模式? [英] Regex Pattern help: finding HTML pattern when nested ASP.NET Eval?
问题描述
Pattern = ((<\/?[\w\s="/.':;#-\/]+>)|(<\%@[\s\S]+\"\s%>))
在使用这个作为测试语法:
When using this as a testing syntax:
<%@ Page Language="C#" %>
<td class="c1 c2 c3" colspan="2">
lorem ipsum
<div class="d1" id="div2" attrid="<%# Eval("CategoryID") %>">
testing 123
</div>
asdf
</td>
和这是一样的上面刚刚添加行号,这样我就可以更方便地问我的问题:
and this is the same as above just added line numbers, so I can more easily ask my question:
1. <%@ Page Language="C#" %>
2. <td class="c1 c2 c3" colspan="2">
3. lorem ipsum
4. <div class="d1" id="div2" attrid="<%# Eval("CategoryID") %>">
5. testing 123
6. </div>
7. asdf
8. </td>
该正则表达式模式正确地匹配线1,2,6和8中,但只是部分地相匹配线4:
它只匹配的这部分线路4:
That RegEx pattern correctly matches lines 1, 2, 6, and 8, but only partially matches line 4: It only matches this part of line 4:
<%# Eval("CategoryID") %>
但我想它的整条生产线相匹配4号线:
But I want it to match the entire line of line 4:
<div class="d1" id="div2" attrid="<%# Eval("CategoryID") %>">
帮助?
推荐答案
试试这个对于 PCRE
<(([^<>]|(?R))*)>
演示: https://regex101.com/r/tE8nJ1/2
和本作的 .NET
(?'o'<)(.*)(?'-o'>)+
演示:<一href=\"http://regexstorm.net/tester?p=(%3f%27o%27%3c)(.*)(%3f%27-o%27%3e)%2b&i=%3c%25%40+Page+Language%3d%22C%23%22+%25%3e%0d%0a%3ctd+class%3d%22c1+c2+c3%22+colspan%3d%222%22%3e%0d%0alorem+ipsum%0d%0a%3cdiv+class%3d%22d1%22+id%3d%22div2%22+attrid%3d%22%3c%25%23+Eval(%22CategoryID%22)+%25%3e%22%3e%0d%0atesting+123%0d%0a%3c%2fdiv%3e%0d%0aasdf%0d%0a%3c%2ftd%3e\"相对=nofollow>链接
或者
(?'o'<)([^<>]*)(?'-o'>)+
要限制捕获组,如果你没有行之间使用换行符。
to restrict capturing group, if you don't use newlines between lines.
这篇关于正则表达式的帮助:当嵌套ASP.NET评估和演示找到HTML模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!