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

前端之家收集整理的这篇文章主要介绍了正则================================================前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//直接提取文字 @H_301_0@ public string StripHTML(string strHtml,string content) @H_301_0@ { @H_301_0@ if (!string.IsNullOrEmpty(strHtml)) @H_301_0@ { @H_301_0@ return SubStr(strHtml,50); @H_301_0@ } @H_301_0@ else @H_301_0@ { @H_301_0@ string[] aryReg ={ @H_301_0@ @"<script[^>]*?>.*?</script>",@H_301_0@ @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",@H_301_0@ @"([\r\n])[\s]+",@H_301_0@ @"&(quot|#34);",@H_301_0@ @"&(amp|#38);",@H_301_0@ @"&(lt|#60);",@H_301_0@ @"&(gt|#62);",@H_301_0@ @"&(nbsp|#160);",@H_301_0@ @"&(iexcl|#161);",@H_301_0@ @"&(cent|#162);",@H_301_0@ @"&(pound|#163);",@H_301_0@ @"&(copy|#169);",@H_301_0@ @"&#(\d+);",@H_301_0@ @"-->",@H_301_0@ @"<!--.*\n" @H_301_0@ @H_301_0@ }; @H_301_0@ @H_301_0@ string[] aryRep = { @H_301_0@ "",@H_301_0@ "",@H_301_0@ "\"",@H_301_0@ "&",@H_301_0@ "<",@H_301_0@ ">",@H_301_0@ " ",@H_301_0@ "\xa1",//chr(161),@H_301_0@ "\xa2",//chr(162),@H_301_0@ "\xa3",//chr(163),@H_301_0@ "\xa9",//chr(169),@H_301_0@ "\r\n",@H_301_0@ "" @H_301_0@ }; @H_301_0@ @H_301_0@ string newReg = aryReg[0]; @H_301_0@ string strOutput = content; @H_301_0@ for (int i = 0; i < aryReg.Length; i++) @H_301_0@ { @H_301_0@ Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase); @H_301_0@ strOutput = regex.Replace(strOutput,aryRep[i]); @H_301_0@ } @H_301_0@ @H_301_0@ strOutput.Replace("<",""); @H_301_0@ strOutput.Replace(">",""); @H_301_0@ strOutput.Replace("\r\n",""); @H_301_0@ @H_301_0@ @H_301_0@ return SubStr(strOutput,50); @H_301_0@ } @H_301_0@ @H_301_0@ } @H_301_0@ @H_301_0@ @H_301_0@ #region 截取字符串 @H_301_0@ public string SubStr(object ostr,object olength) @H_301_0@ { @H_301_0@ string title = ostr.ToString(); @H_301_0@ int length = int.Parse(olength.ToString()); @H_301_0@ if (title.Length > length) @H_301_0@ { @H_301_0@ title = title.Substring(0,length).ToString() + ".."; @H_301_0@ } @H_301_0@ return title; @H_301_0@ } @H_301_0@

#endregion

@H_301_0@

@H_301_0@

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

猜你在找的正则表达式相关文章