日期:2014-05-18  浏览次数:21223 次

求正则匹配下面HTML代码中的03、07、09、15、24、25、16这几个数字
<td><a href="/lottery/draw/view/50">双色球</a></td> <td>2012026期</td> <td>2012-03-06</td> <td> <div class="ballbg">  
<span class="ball_1">03</span>  
<span class="ball_1">07</span>  
<span class="ball_1">09</span>  
<span class="ball_1">15</span>  
<span class="ball_1">24</span>  
<span class="ball_1">25</span> <span class="ball_2">16</span>

  </div>  


</td> 


怎么写正则表达式 能正确匹配出这几个数字???求帮助

------解决方案--------------------
换一下,没注意class="ball_2"这个
(?<=<span>)(.*)(?=</span>)
------解决方案--------------------
C# code
        string s = @"<td><a href=""/lottery/draw/view/50"">双色球</a></td> <td>2012026期</td> <td>2012-03-06</td> <td> <div class=""ballbg"">   
<span class=""ball_1"">03</span>   
<span class=""ball_1"">07</span>   
<span class=""ball_1"">09</span>   
<span class=""ball_1"">15</span>   
<span class=""ball_1"">24</span>   
<span class=""ball_1"">25</span> <span class=""ball_2"">16</span>
  </div>   
</td>";
        MatchCollection matches = Regex.Matches(s, @"(?is)(?<=双色球.*?)<span class=""ball_\d"">(\d+)</span>(?=.*?</div>)");
        foreach (Match match in matches)
            Response.Write(match.Groups[1].Value + "<br/>");

------解决方案--------------------
探讨
引用:
C# code

string s = @"<td><a href=""/lottery/draw/view/50"">双色球</a></td> <td>2012026期</td> <td>2012-03-06</td> <td> <div class=""ballbg"">
<span class=""ball_1"">03</span>
<s……

------解决方案--------------------
C# code
        string s = @"<td><a href=""/lottery/draw/view/50"">双色球</a></td> <td>2012026期</td> <td>2012-03-06</td> <td> <div class=""ballbg"">   
<span class=""ball_1"">03</span>   
<span class=""ball_1"">07</span>   
<span class=""ball_1"">09</span>   
<span class=""ball_1"">15</span>   
<span class=""ball_1"">24</span>   
<span class=""ball_1"">25</span> <span class=""ball_2"">16</span>
  </div>   
</td>";
        MatchCollection matches = Regex.Matches(s, @"(?is)(?<=双色球</a></td>\s+<td>\d+期</td>.*?)<span class=""ball_\d"">(\d