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

正则表达式
自定义ubb代码,preg_replace()函数的一些代码
eregi_replace()中特殊字符的处理方法
eregi_replace与preg_replace 函数代码的用法比较
JS正则表达式详解[收藏]
[正则表达式]贪婪模式与非贪婪模式
收集的ASP.NET中常用正则表达式
C#正则实现Ubb解析类的代码
利用正则快速找出两个字符串的不同字符
C#中的正则表达式 学习资料
正则表达式中对各字符集编码范围的总结
正则表达式基础教程与说明
正则表达式
asp下正则实现URL自动链接的一个函数
JS:一个匹配日期的正则
JS:正则将首字单词转成大写
正则表达式:过滤<font>和</font>
vbs:把一段文字中指定字符颜色变成红色的正则
js:校验IPv6地址的正则表达式
vbs:一段比较精简的代码实现取得字符串的"字节"数
vbs:能算出一个字符在一字段里共出现有几次的函数

用正则表达式过滤html代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 35 ::
收藏到网摘: 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 %>