利用正则表达式去掉字符串中所有html内容,得到所有文本内容,去掉的内容有:div,img,超连接,script脚本等html内容。将以下例子保存为asp文件,运行一下就知道效果了。

  1. <%  
  2. Function RemoveHTML( strText )  
  3. Dim RegEx  
  4.  
  5. Set RegEx = New RegExp  
  6.  
  7. RegEx.Pattern = "<[^>]*>" 
  8. RegEx.Global = True  
  9.  
  10. RemoveHTML = RegEx.Replace(strText, "")  
  11. End Function  
  12.  
  13. str="<html><body><a href=""a.asp"">打开</a><img src=""1.jpg""><div class=""a3"">aaa</div></body></html>" 
  14. response.write removehtml(str)  
  15. %> 

本日志由 胡子 于 2008-09-14 21:17:41 发表到 学习随笔 中,目前已经被浏览 1359 次,评论 0 次;

作者添加了以下标签: asp正则表达式去掉字符串所有html内容