62,074
社区成员
发帖
与我相关
我的任务
分享
public string checkStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, "");
html = regex2.Replace(html, "");
html = regex3.Replace(html, " _disibledevent=");
html = regex4.Replace(html, "");
html = regex5.Replace(html, "");
html = regex6.Replace(html, "");
html = regex7.Replace(html, "");
html = regex8.Replace(html, "");
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}
/// <summary>
/// 删除字符串中指定的内容,不区分大小写
/// </summary>
/// <param name="src">要修改的字符串</param>
/// <param name="pattern">要删除的正则表达式模式</param>
/// <returns>已删除指定内容的字符串</returns>
public static string DropIgnoreCase(string src, string pattern)
{
return ReplaceIgnoreCase(src, pattern, "");
}
string str = @"<p><span style=""background-color: #800000"">hahhhhdsadas</span></p>...</span>";
str = System.Text.RegularExpressions.Regex.Replace(str,@"<(?!/?p(\s|>)+)[^>]*?>","", RegexOptions.IgnoreCase);
Response.Write(str);
/// <summary>
/// 去掉html内容中的指定的html标签
/// </summary>
/// <param name="content">html内容</param>
/// <param name="tagName">html标签</param>
/// <returns>去掉标签的内容</returns>
public static string DropHtmlTag(string content, string tagName)
{
//去掉<tagname>和</tagname>
return DropIgnoreCase(content, "<[/]{0,1}" + tagName + "[^\\>]*\\>");
}
/// <summary>
/// 去掉html内容中全部标签
/// </summary>
/// <param name="content">html内容</param>
/// <returns>去掉html标签的内容</returns>
public static string DropHtmlTag(string content)
{
//去掉<*>
return Drop(content, "<[^\\>]*>");
}
/// <summary>
/// 删除字符串中指定的内容
/// </summary>
/// <param name="src">要修改的字符串</param>
/// <param name="pattern">要删除的正则表达式模式</param>
/// <returns>已删除指定内容的字符串</returns>
public static string Drop(string src, string pattern)
{
return Replace(src, pattern, "");
}
<p><span style="background-color: #800000">hahhhhdsadas</span></p>...</span>