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;
}
查看全文
相关阅读:
37. Sudoku Solver(js)
36. Valid Sudoku(js)
35. Search Insert Position(js)
34. Find First and Last Position of Element in Sorted Array(js)
33. Search in Rotated Sorted Array(js)
32. Longest Valid Parentheses(js)
函数的柯里化
俞敏洪:我和马云就差了8个字
vue路由传值params和query的区别
简述vuex的数据传递流程
原文地址:https://www.cnblogs.com/wang123/p/505758.html
最新文章
学习python语言
开发小账本
梦断代码阅读笔记02
开发小账本
开发小账本
梦断代码阅读笔记01
51. N-Queens(js)
50. Pow(x, n)(js)
49. Group Anagrams(js)
48. Rotate Image(js)
热门文章
47. Permutations II(js)
46. Permutations(js)
45. Jump Game II(js)
44. Wildcard Matching(js)
43. Multiply Strings(js)
42. Trapping Rain Water(js)
41. First Missing Positive(js)
40. Combination Sum II(js)
39. Combination Sum(js)
38. Count and Say(js)
Copyright © 2011-2022 走看看