【发布时间】:2015-08-19 15:47:50
【问题描述】:
我有以下 HTML 文件结构:
<table>
<tr class="heading">
<td colspan="2">
<h2 class="groupheader">Public Types</h2>
<!-- I don't want that! We're in a table.-->
</td>
</tr>
<tr>...</tr>
</table>
<h2 class="groupheader">Detailed Description</h2>
<!-- I want all that until the next h2-->
<div class="textblock"><p>Provides the functions to control the generation of a single data log file. </p>
<h4>Example</h4>
<div class="fragment"><div class="line">Test <a href="aaa">stuff</a>();</div>
<div class="line">...</div>
<div class="line">...</div>
</div>
</div> <!-- end of first result -->
<h2 class="groupheader">Member</h2>
<!-- I want all that until the next h2 or hr-->
<a class="anchor"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="...">test</a></td>
</tr>
</table>
</div><div class="memdoc">
<hr><!-- End of 2nd result -->
使用正则表达式,我需要获取每个标题之间的所有内容,直到下一个标题或 hr 标记,期待它是否在表格中。
到目前为止,我已经获得了我所有的 h2->h2|hr 内容。它是这样的:
(?s)(<h2 class="groupheader">.*?)(<h2|<hr)
如何跳过表格中包含的 H2 下的内容?我试过带着消极的表情在后面胡思乱想,但我没有得到任何结果。
感谢您的帮助。
【问题讨论】:
-
您似乎有一些拼写错误使我无法理解这个问题,您能改正它们吗?也许提供一些示例数据和示例输出?
-
你需要得到什么,不明白,请添加一个例子以及它是如何失败的
-
我试图澄清我的问题。希望越来越好!
-
这将是超级丑陋的,如果不是完全不可能单独使用正则表达式的话。使用 DOM 解析器会更好
-
如果您提及您使用正则表达式的语言/程序会有所帮助。这在没有 可变宽度 负向后视的情况下单独使用正则表达式基本上是不可能的,许多语言/程序不支持这一点
标签: html regex tags negative-lookbehind