Regex regexHtmlComment = new Regex(@"<![^>]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
Regex regexHtmlLink = new Regex(@"<a\b[^>]+>(?<l>.+?)<*/a>", RegexOptions.Compiled| RegexOptions.IgnoreCase | RegexOptions.Singleline);
Regex regexHtmlTag = new Regex(@"<[^>]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
text =regexHtmlComment.Replace(text, " ");
text =regexHtmlLink.Replace(text, "${l}");
text =regexHtmlTag.Replace(text, " ");
本文介绍了一种使用正则表达式清理HTML文档的方法,通过三个具体的正则表达式实例:HTML注释、链接及标签的匹配与替换,实现了对HTML文档的有效清理。
5万+

被折叠的 条评论
为什么被折叠?



