提取HTML标签的正则表达式解决方案(圣诞快乐,强烈推荐)

1<font color="red">
2<hr size="1"/>
3   
4上面这样的标签当然很好处理,可是如果混合了 Javascript 的标签或者有自定义属性的标签,提取起来就有很大难度,比如下面这样的:   
5  
6<img align="right" border="0" dragenabled="" name="TopicImg" onclick="javascript:if(this.style.cursor=='hand'){var nw=window.open('about:blank','_blank','');nw.document.open();nw.document.write('&lt;img src='+this.src+'&gt;');nw.document.close();nw.document.title='查看';nw=null;}" onload="javascript:if(this.style.width&gt;600){this.style.width=600;this.style.cursor='hand';}" src="/ucgi/ubb_view.cgi?ubb=view;up=AllCHN;f=13;file=45.jpg" ubb=""/>   
7  
8这里提供一个正则表达式,可以解决这个问题:   
9/&lt;\/?\w+(\s+\S+?(=([\'\"]?).*?[^\\\\]\3)?)*\W*&gt;/</font>
Published At
Categories with Web编程
comments powered by Disqus