相关疑难解决方法(0)

匹配对标记与正则表达式

我正在尝试从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>
Run Code Online (Sandbox Code Playgroud)

id ="welcome"的content_block结束标记实际上被匹配为第一个打开的content_block标记的结束标记.

我正在使用的正则表达式是:

/<content_block id="(.*)">([\w\W]*?)<\/content_block>/i
Run Code Online (Sandbox Code Playgroud)

关于我失败的地方的任何指示?

regex html-parsing

2
推荐指数
1
解决办法
5968
查看次数

标签 统计

html-parsing ×1

regex ×1