2010-07-31 97 views
1

我试图找到一个VBScript的正则表达式来从字符串中删除一些html标签及其内容。现在如何删除一些html标签?

的字符串,

<H2>Title</H2><SPAN class=tiny>Some 
text here</SPAN><LI>Some list 
here</LI><SCRITP>Some script 
here</SCRITP><P>Some text here</P> 

,我想排除<SPAN class=tiny>Some text here</SPAN><SCRITP>Some script here</SCRITP>

也许有人有这种简单的解决方案,谢谢。

+0

什么是字符串?你知道,它似乎已经完成了它对HTML的操作,并且不显示标签。 – cofiem 2010-07-31 05:45:08

回答

0

你可以这样做容易得多using css

span.tiny { 
    display: none; 
} 

或使用jQuery

$("span.tiny").hide(); 
+1

这不会删除脚本标记。 – 2010-08-04 03:03:05

4

这应该做的伎俩在VBScript:

Dim myRegExp, ResultString 
Set myRegExp = New RegExp 
myRegExp.IgnoreCase = True 
myRegExp.Global = True 
myRegExp.Pattern = "<span class=tiny>[\s\S]*?</span>|<script>[\s\S]*?</script>" 
ResultString = myRegExp.Replace(SubjectString, "") 

SubjectString是变量与您的原始HTML和ResultString收到所有出现的两个标签被删除的HTML。

注意:我假设scritp在您的示例中是script的拼写错误。如果不是,请相应地调整我的代码示例。

+0

+1,尽管由于HTML不是正则语言,所以根本就不可能使用RE操纵HTML。使用DOM树是好得多,但是完全不同的方法。 – 2010-12-31 02:29:31

0

我想你想这

$(function(){ 
$('span.tiny').remove(); 
$('script').remove(); 
})