下面這段代碼,不會替換ld<sad中間的<,所以內容仍然是正常的
復制代碼 代碼如下:
<%
function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(\<.[^\<]*\>)"
str=re.replace(str," ")
re.Pattern="(\<\/[^\<]*\>)"
str=re.replace(str," ")
str=replace(str," ","")
str=replace(str," ","")
nohtml=str
set re=nothing
end function
str="<title>sadjksjdl歡迎你sajdljsald<sadsadsad<br>" '這裡是測試
response.write nohtml(str)
%>
結果為:
復制代碼 代碼如下:
sadjksjdl歡迎你sajdljsald<sadsadsad
不過下面的代碼是不問的,直接看到<就忘後面無限制的匹配
復制代碼 代碼如下:
<%
Function dropHtml(Byval strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍歷匹配集合,並替換掉匹配的項目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
dropHtml=strHTML
Set objRegExp = Nothing
End Function
str="<title>sadjksjdl歡迎你sajdljsald<sadsadsad<br>" '這裡是測試
response.write dropHtml(str)
%>
結果為:
復制代碼 代碼如下:
sadjksjdl歡迎你sajdljsald