2010-07-31 117 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(); 
})