Fork me on GitHub

.NET Regular Expressions

HTML去空白回车换行
private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s*", RegexOptions.Compiled);
private static readonly Regex REGEX_LINE_SPACE = new Regex(@"\n\s*\r", RegexOptions.Compiled);
private static readonly Regex REGEX_SPACE = new Regex(@"( )+", RegexOptions.Compiled);

var targetHtml = REGEX_SPACE.Replace(REGEX_LINE_SPACE.Replace(REGEX_LINE_BREAKS.Replace(baseInfoHtml, ""), ""), " ");

Ref:正则表达式30分钟入门教程

Ref:常用正则表达式

Ref:Matching Balanced Constructs with .NET Regular Expressions

Ref:RegexOne

Ref:RegExLib

Ref:Regex101

Ref:http://regexlib.com/Default.aspx

posted @ 2012-12-11 16:10  Nick.Chung  阅读(146)  评论(0编辑  收藏  举报