当前位置: 首页 > 图文教程 > 网络编程 > 正则表达式 > 用正则表达式过滤html代码

正则表达式
[原创]正则匹配后面非指定字符的正则
正则的几个基本概念
php半小时精通正则表达式
一个不错的正则
自己学正则时做的笔记,其实正则也不难哦 php
关于HTML及UBB标记的闭合
用JavaScript实现全局替换,解决$等特殊符号的难题[
正则表达式的基本知识
临时记录:一个正则
一个关于正则表达式的问题
正则表达式不包含align该怎么写
正则表达式话题
Javascrp中几个常用的字符串验证
Js&Vbs正则表达式替换重复的字符
一个验证用户名的正则表达式
正则表达式,只匹配一次下化线!
用JS让文章内容指定的关键字加亮
看到一个JS正则的题
Javascript里的两种使用正则的方法
正则表达式 应用四则

用正则表达式过滤html代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 30 ::
收藏到网摘: n/a

代码例子如下:
<%
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 %>