用正則表達式過濾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
%>
<form method="post" id=form1 name=form1>
<b>Enter an HTML String:</b><br>
<textarea name="txtHTML" cols="50" rows="8" wrap="virtual"><%=Request("txtHTML")%></textarea>
<p>
<input type="submit" value="Strip HTML Tags!" id=submit1 name=submit1>
</form>
<% if Len(Request("txtHTML")) > 0 then %>
<p><hr><p>
<b><u>View of string <i>with no</i> HTML stripping:</u></b><br>
<xmp>
<%=Request("txtHTML")%>
</xmp><p>
<b><u>View of string <i>with</i> HTML stripping:</u></b><br>
<pre>
<%=StripHTML(Request("txtHTML"))%>
</pre>
<% End If %>
相關(guān)文章
python和JavaScript的正則表達式詳細(xì)使用對比
正則表達式是對字符串提取的一套規(guī)則,我們把這個規(guī)則用正則里面的特定語法表達出來,去匹配滿足這個規(guī)則的字符串,這篇文章主要給大家介紹了關(guān)于python和JavaScript正則表達式詳細(xì)使用對比的相關(guān)資料,需要的朋友可以參考下2024-05-05
正則表達式中的正向預(yù)查和負(fù)向預(yù)查實例分析
這篇文章主要介紹了正則表達式中的正向預(yù)查和負(fù)向預(yù)查,實例分析了正向預(yù)查和負(fù)向預(yù)查的概念與具體用法,具有一定參考借鑒價值,需要的朋友可以參考下2015-01-01
淺談?wù)齽t表達式(Regular Expression)
本文介紹了正則表達式的一些學(xué)習(xí)內(nèi)容,以及在Javascript、PHP下如何使用正則表達式2014-08-08

