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

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

问题描述

我正在寻找一个regex来匹配所有HTML标签,除了< p> < / p> 包括标记内容。我在ColdFusion中开发。



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

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

 < em>这里有一些文字< / em> 

但不包括

 < p>这里有一些文字和标签< / p>有关如何完成此任务的任何想法吗?

h2_lin>解决方案

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



你最好使用某种DOM-并找到您需要的元素。


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.

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>

and

<em>Some text here</em>

but not

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

Any ideas on how to accomplish this?

解决方案

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

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

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

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