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;
}
查看全文
相关阅读:
连通域标记
qt&gdal
gdal vs2013编译
java配置
windows下面安装Python和pip
mfc operator new”: 没有重载函数接受 3 个参数
std::min&std::max与mfc冲突问题
qt中vtk易出现错误
cmake构建qt工程
Webstorm补丁
原文地址:https://www.cnblogs.com/wang123/p/505758.html
最新文章
《转》Objective-C Runtime(2)- Object & Class & Meta Class
《转》Objective-C Runtime(1)- Self & Super
《转》Multithread 什么时候处理多线程,有几种方式,优缺点?
【iOS学习笔记】一些问题
【iOS学习笔记】常用代码
【iOS学习笔记】面试题归总
【iOS学习笔记】block
【iOS 学习笔记】iOS中runtime机制
【iOS学习笔记】iOS中的MVC设计模式
【iOS学习笔记】用collectionView解决大量button的性能问题
热门文章
【iOS学习笔记】Objective-C中根据函数名调用函数
【iOS学习笔记】c语言问题
【iOS学习笔记】在iOS开发中使用FMDB
af
通知
自定义控件时,初始化的注意事项
UINavgationViewController
UITableview中的backgroundView
UIImageView显示问题
编译第三方库debug和release不同文件形式的编译
Copyright © 2011-2022 走看看