当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

asp利用正则去掉字符串中所有html内容

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:31:28

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

<
%
Function 
RemoveHTML( 
strText 
)
Dim 
RegEx

Set 
RegEx 

New 
RegExp

RegEx.Pattern 

"
<
[^>
]*>
"

RegEx.Global 

True

RemoveHTML 

RegEx.Replace(strText, 
"
"
)
End 
Function

str="
<
html>
<
body>
<

href="
"
a.asp"
"
>
打开<
/a>
<
img 
src="
"
1.jpg"
"
>
<
div 
class="
"
a3"
"
>
aaa<
/div>
<
/body>
<
/html>
"

response.write 
removehtml(str)
%>


asp利用正则去掉字符串中所有html内容