日期:2014-05-18 浏览次数:21159 次
<li class="h4">x1x</li><li class="h4">x2x</li><li class="h4">xfx</li><li class="h4">xsx</li>
string htmlStr = @"<li class=""h4"">x1x</li><li class=""h4"">x2x</li><li class=""h4"">xfx</li><li class=""h4"">xsx</li>"; Regex re = new Regex(@"(?<=<li\s*class=""h4"">)[^<]+(?=</li>)", RegexOptions.None); MatchCollection mc = re.Matches("text"); foreach (Match ma in mc) { //ma.Value就是你要值 }
------解决方案--------------------
var reg = new Regex("<li[^>]*class=(['\"])h4\\1[^>]*>(?<content>.*?)</li>", RegexOptions.IgnoreCase); const string str = "<li class=\"h4\">x1x</li><li class=\"h4\">x2x</li><li class=\"h4\">xfx</li><li class=\"h4\">xsx</li>"; var ms = reg.Matches(str); foreach (Match match in ms) { Console.WriteLine(match.Groups["content"].Value); }