处理特殊字符和移掉内联样式

梦为马

关注

阅读 151

2022-12-01


#region  处理特殊字符

public static string DisposalSpecial(string regexStr)
{
var regex = new Regex("([\\\\\\^\\$\\+\\?\\{\\}\\?\\(\\)\\!\\-\\[\\]\\+\\/])");
string rel = regex.Replace(regexStr, "\\$1");
rel= rel.Replace(" ", "\\s");
return rel;
}

#endregion

#region 移掉内联样式

public static string RemoveStyle(string html)
{
if (string.IsNullOrEmpty(html))
{
return string.Empty;
}
return Regex.Replace(html, "style=\\\"[\\s\\S]*?\\\"", string.Empty, RegexOptions.IgnoreCase);
}

#endregion

通过上述方法,可以移除html中的内联样式,方便自定义自己的统一样式。


精彩评论(0)

0 0 举报