js去掉HTML标记
2008-07-23 11:20
369 查看
private string StripHTML(string strHtml)
{
string [] aryReg ={
@"<script[^>]*?>.*?</script>",
@"<(///s*)?!?((/w+:)?/w+)(/w+(/s*=?/s*(([""'])(%7c[%5e/7])*?%207|%20w+)|.{0})|%20s)*?(%20/%20s]//[""'tbnr]|[^/7])*?/7|/w+)|.{0})|/s)*?(///s*)?>",
@"([/r/n])[/s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"(/d+);",
@"-->",
@"<!--.*/n"
};
string [] aryRep = {
"",
"",
"",
"/"",
"&",
"<",
">",
" ",
"/xa1",//chr(161),
"/xa2",//chr(162),
"/xa3",//chr(163),
"/xa9",//chr(169),
"",
"/r/n",
""
};
string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++)
{
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace("<","");
strOutput.Replace(">","");
strOutput.Replace("/r/n","");
return strOutput;
}
{
string [] aryReg ={
@"<script[^>]*?>.*?</script>",
@"<(///s*)?!?((/w+:)?/w+)(/w+(/s*=?/s*(([""'])(%7c[%5e/7])*?%207|%20w+)|.{0})|%20s)*?(%20/%20s]//[""'tbnr]|[^/7])*?/7|/w+)|.{0})|/s)*?(///s*)?>",
@"([/r/n])[/s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"(/d+);",
@"-->",
@"<!--.*/n"
};
string [] aryRep = {
"",
"",
"",
"/"",
"&",
"<",
">",
" ",
"/xa1",//chr(161),
"/xa2",//chr(162),
"/xa3",//chr(163),
"/xa9",//chr(169),
"",
"/r/n",
""
};
string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++)
{
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace("<","");
strOutput.Replace(">","");
strOutput.Replace("/r/n","");
return strOutput;
}
相关文章推荐
- 中正则表达式,js去掉html标记,去掉字符,截取字符
- js 去掉html标记 去掉换行
- js去掉所有html标记的函数
- js去掉html标记,去掉字符,截取字符
- 正则表达式,js去掉html标记,去掉字符,截取字符
- 正则表达式,js去掉html标记,去掉字符,截取字符
- js正则去掉HTML标记保留img
- js去掉字符串中所有的html标记
- js 客户端打印html 并且去掉页眉、页脚的实例
- j2ee的web工程,jsp、html、js文件有叉号,怎么去掉自动验证,我不想看到叉号
- 通过js去掉所有的html标签,得到HTML标签中的所有内容
- 从HTML代码中提取文字,去掉HTML的标记
- C#、JS利用正则表达式清理HTML标记一例
- 使用C#将HTML文本转换为普通文本,去掉所有的Html标记
- js 去掉html标签
- js去掉html标签和去掉字符串文本的所有的空格
- asp.net如何去掉HTML标记
- asp.net去掉HTML标记
- 去掉html标签的js
- 去掉字符串不需要的HTML标记(正则表达式)