c# 正则删除 html代码,C# 替换去除HTML标记方法(正则表达式)

  • Post author:
  • Post category:其他


usingSystem.Text.RegularExpressions;//包含正则表达式

publicstaticstringNoHTML(stringHtmlstring)//去除HTML标记

{

//删除脚本

Htmlstring = Regex.Replace(Htmlstring, @””,””, RegexOptions.IgnoreCase);

//删除HTML

Htmlstring = Regex.Replace(Htmlstring, @”]*)>”,””, RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @”([\r\n])[\s]+”,””, RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @”–>”,””, RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @””, “”, RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @””,

@””,

@”