正则表达式匹配所有 HTML 标签和标签内容,除了 <p>和 </p> [英] Regex to match all HTML tags and tag content except <p> and </p>

查看:28
本文介绍了正则表达式匹配所有 HTML 标签和标签内容,除了 <p>和 </p>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个匹配所有 HTML 标记的正则表达式,除了包含标记内容的 <p></p>.我正在使用 ColdFusion 进行开发.

I am looking for a regex to match all HTML tags, except <p> and </p> that includes the tag content. I am developing in ColdFusion.

有一个较早的帖子关于除了 <p></p> 之外的匹配标签,但我还需要抓取标签之间的所有内容.例如,以下内容应完全匹配:

There was an earlier post about matching tags except <p> and </p>, but I need to grab everything between the tags as well. For instance, the following should match in their entirety:

<a href="http://www.google.com">Google</a>

<em>Some text here</em>

但不是

<p>Some text and tags here</p>

关于如何实现这一点的任何想法?

Any ideas on how to accomplish this?

推荐答案

使用正则表达式解析 HTML 非常非常困难和痛苦.

Parsing HTML using regular expressions is very very hard and painful.

您最好使用某种基于 DOM 的解析器并找到您需要的元素.

You're better off using some sort of DOM-based parser and finding the elements you need.

这篇关于正则表达式匹配所有 HTML 标签和标签内容,除了 &lt;p&gt;和 &lt;/p&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆