正則表達(dá)式再次讓我震撼,寥寥數(shù)行代碼就可以完成普通代碼不易實(shí)現(xiàn)的功能,至少是實(shí)現(xiàn)起來(lái)比較復(fù)雜的功能。
一、清楚內(nèi)容中的Javsscript 代碼 復(fù)制代碼代碼如下:
Function ClearJSCode(originCode)
Dim reg
set reg = New RegExp
reg.Pattern = "<SCRIPT[^<]*</SCRIPT>"
reg.IgnoreCase = True
reg.Global = True
clearJSCode = reg.Replace(originCode, "")
End Function
二、清除內(nèi)容中的HTML代碼 復(fù)制代碼代碼如下:
Function ClearHTMLCode(originCode)
Dim reg
set reg = new RegExp
reg.Pattern = "<[^>]*>"
reg.IgnoreCase = True
reg.Global = True
ClearHTMLCode = reg.Replace(originCode, "")
End Function
現(xiàn)在好多網(wǎng)站的內(nèi)容都是使用采集程序生成的,使用上邊的代碼就可以輕松的將內(nèi)容中的HTML和JS代碼清除掉。