/// <summary> /// 检查字符串中是否有Html标签 /// </summary> /// <param name="html">Html源码</param> /// <returns>存在为True</returns> public static bool CheckHtml(string html) { string filter = "<[\\s\\S]*?>"; if (Regex.IsMatch(html, filter)) { return true; } filter = "[<>][\\s\\S]*?"; if (Regex.IsMatch(html, filter)) { return true; } return false; }
/// <summary> /// 返回过滤掉所有的Html标签后的字符串 /// </summary> /// <param name="html">Html源码</param> /// <returns>过滤Html标签后的字符串</returns> public static string ClearAllHtml(string html) { string filter = "<[\\s\\S]*?>"; if (Regex.IsMatch(html, filter)) { html = Regex.Replace(html, filter, ""); } filter = "[<>][\\s\\S]*?"; if (Regex.IsMatch(html, filter)) { html = Regex.Replace(html, filter, ""); } return html; }