/// <summary>
/// 去除标签里面的属性保留IMG标签属性
/// </summary>
/// <param name="strText"></param>
/// <returns></returns>
public static string ClearAttrByHtml(string strText)
{
if (string.IsNullOrEmpty(strText)) { return ""; }
return Regex.Replace(strText, @"<((?!IMG)[a-zA-Z]+)s*[^><]*>", "<$1>", RegexOptions.IgnoreCase);
}
(?!IMG)核心代码,当IMG成功匹配时否定整个正则表达式