JavaScript中的RegEx:两个标记之间的内容

时间:2016-05-12 09:52:39

标签: javascript html regex xml find

我需要在两个XML标记之间提取内容,不包括标记。

PS:我不会用它来解析XML。我将在JavaScript中使用RegEx,因此lookbehind不起作用。

我做错了什么?

XML:

<location maps="">
    RewriteMap map txt:map.txt
    RewriteMap lower int:tolower
    RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
    RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
    RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]
</location>

正则表达式:

/(?:(?=(\<(?!\/)(.*?)\>)))([\s\S]*?)(?=(\<(?=\/)(.*?)\>))/igm

结果:

<location maps="">
    RewriteMap map txt:map.txt
    RewriteMap lower int:tolower
    RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
    RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
    RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]

我想要什么

RewriteMap map txt:map.txt
RewriteMap lower int:tolower
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]

1 个答案:

答案 0 :(得分:0)

怎么样

<(\w+)[^>]+>\n*([\s\S]*)<\/\1>

它会抓取您的标记,将所有内容捕获到以/为前缀的重复标记。

捕获组2的结果。

Check it out here at regex101