【发布时间】:2010-12-14 03:37:21
【问题描述】:
我正在尝试从 xhtml 文档中检索特定标签及其内容,但它匹配错误的结束标签。
在以下内容中:
<cache_namespace name="content">
<content_block id="15">
some content here
<cache_namespace name="user">
<content_block id="welcome">
Welcome Apikot!
</content_block>
</cache_namespace>
</content_block>
</cache_namespace>
id="welcome" 的 content_block 结束标记实际上匹配为第一个开始 content_block 标记的结束标记。
我使用的正则表达式是:
/<content_block id="(.*)">([\w\W]*?)<\/content_block>/i
关于我在哪里失败的任何指示?
【问题讨论】:
-
为什么不使用 XPath?
-
你能保证缩进吗?
标签: regex html-parsing