日期:2014-05-17  浏览次数:20932 次

c# 正则循环错误 麻烦帮看看 速结

  for (int i = 0; i < 10; i++)
  {
  MatchCollection mc = Regex.Matches(html, @"<li class=['""]top-"+i+"['""]>(?<text>[\s\S]*?)</li>", RegexOptions.IgnoreCase);
  string chulihtml = "";
  foreach (Match m in mc)
  {

  chulihtml = m.Groups["text"].Value;
  break;
  }
  }
这个位置 不对top-"+i+"

如果想循环的话 怎么写呢?

------解决方案--------------------
修改下 
C# code
Regex re = new Regex(@"<li class=['\""]top-\d['\""]>(?<text>[\s\S]*?)</li>", RegexOptions.None);
MatchCollection mc = re.Matches("text");
foreach (Match ma in mc)
{
}

------解决方案--------------------
这样 
MatchCollection mc = Regex.Matches(html, @"<li class=['""]top-"+i.ToString()+@"['""]>(?<text>[\s\S]*?)</li>", RegexOptions.IgnoreCase);