zoukankan
html css js c++ java
利用正则表达式去掉html代码
using
System.Text.RegularExpressions;
//
需要引用
//
利用正则表达式去掉"<"和">"之间的内容
private
string
StripHT(
string
strHtml)
{
Regex regex
=
new
Regex(
"
<.+?>
"
,RegexOptions.IgnoreCase);
string
strOutput
=
regex.Replace(strHtml,
""
);
return
strOutput;
}
//
方法二(不知为什么此方法占用CPU100%)
public
static
string
DropHTML(
string
strHtml)
{
string
[] aryReg
=
{
@"
<script[^>]*?>.*?</script>
"
,
@"
<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""''])(\\[""''tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>
"
,
@"
([\r])[\s]+
"
,
@"
&(quot|#34);
"
,
@"
&(amp|#38);
"
,
@"
&(lt|#60);
"
,
@"
&(gt|#62);
"
,
@"
&(nbsp|#160);
"
,
@"
&(iexcl|#161);
"
,
@"
&(cent|#162);
"
,
@"
&(pound|#163);
"
,
@"
&(copy|#169);
"
,
@"
&#(\d+);
"
,
@"
-->
"
,
@"
<!--.*
"
}
;
string
[] aryRep
=
{
""
,
""
,
""
,
"
\
""
,
"
&
"
,
"
<
"
,
"
>
"
,
"
"
,
"
\xa1
"
,
//
chr(161),
"
\xa2
"
,
//
chr(162),
"
\xa3
"
,
//
chr(163),
"
\xa9
"
,
//
chr(169),
""
,
"
\r
"
,
""
}
;
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
"
,
""
);
return
strOutput;
}
查看全文
相关阅读:
Python爬取中国疫情的实时数据
文件上传
条件查询和分页(第三周)
全国疫情可视化图表
Jquery的Ajax技术(第二周)
软件工程开课博客
求一个整数数组、环形数组中最大子数组的和
今日所学—Android中ViewPager的使用
今日所学—Android中ExpandableListView的使用
你看,蚂蚁金服都上市了,程序员什么时候才能财富自由呢?
原文地址:https://www.cnblogs.com/wang123/p/505758.html
最新文章
oracle索引使用时注意
oracle的索引维护
oracle 的索引
oracle的散列聚簇表
oracle的簇的管理
一位女程序猿前端学习7天之“旅”的故事
纯js和纯css+html制作的手风琴的效果
中科院电面细节总结
关于360笔试部分题目小结
仓库管理系统
热门文章
课程管理系统
课件中动手动脑5
JAVA项目中的常用的异常处理情况
课件中动手动脑4
可以统计已初始化对象个数的类
课件中动手动脑3
课件中动手动脑2
统计单词频率
课件中动手动脑1
学习总结—购物商城(第四周)
Copyright © 2011-2022 走看看