加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则================================================

发布时间:2020-12-14 01:11:30 所属栏目:百科 来源:网络整理
导读://直接提取文字 public string StripHTML(string strHtml,string content) { if (!string.IsNullOrEmpty(strHtml)) { return SubStr(strHtml,50); } else { string[] aryReg ={ @"script[^]*?.*?/script", @"(/s*)?!?((w+:)?w+)(w+(s*=?s*(([""'])([
//直接提取文字
public string StripHTML(string strHtml,string content)
{
if (!string.IsNullOrEmpty(strHtml))
{
return SubStr(strHtml,50);
}
else
{
string[] aryReg ={
@"<script[^>]*?>.*?</script>",
@"<(/s*)?!?((w+:)?w+)(w+(s*=?s*(([""'])([""'tbnr]|[^7])*?7|w+)|.{0})|s)*?(/s*)?>",
@"([rn])[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),
"rn",
""
};

string newReg = aryReg[0];
string strOutput = content;
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("rn","");


return SubStr(strOutput,50);
}

}


#region 截取字符串
public string SubStr(object ostr,object olength)
{
string title = ostr.ToString();
int length = int.Parse(olength.ToString());
if (title.Length > length)
{
title = title.Substring(0,length).ToString() + "..";
}
return title;
}

#endregion



座机: ((d{3,4})|d{3,4}-|s)?d{8}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读