正則表達式有很多值得學習的地方,你對正則表達式是否熟悉,錯新技術頻道的小編今天將給您講述的是正則表達式過濾HTML代碼的例子,需要的朋友可以參考下其中的內容詳情。
?
代碼例子如下:
<%
Option Explicit
Function stripHTML(strHTML)
'Strips the HTML tags from strHTML
?Dim objRegExp, strOutput
?Set objRegExp = New Regexp
?objRegExp.IgnoreCase = True
?objRegExp.Global = True
?objRegExp.Pattern = "<.+?>"
?'Replace all HTML tag matches with the empty string
?strOutput = objRegExp.Replace(strHTML, "")
?'Replace all < and > with < and >
?strOutput = Replace(strOutput, "<", "<")
?strOutput = Replace(strOutput, ">", ">")
?stripHTML = strOutput 'Return the value of strOutput
?Set objRegExp = Nothing
End Function
%>
?
?
<% if Len(Request("txtHTML")) > 0 then %>
?
?
?View of string with no HTML stripping:
?
?
?
?%=request("txthtml")%>
?
?View of string with HTML stripping:
?
?<%=StripHTML(Request("txtHTML"))%>?
<% End If %>
?
以上就是正則表達式過濾HTML代碼的例子,想必都已有了一定的了解,更多關于正則表達式的內容請繼續關注錯新技術頻道。
?
新聞熱點
疑難解答