有一对<td></td>中的内容动态变化,如何用正则取值:有变价时显示为:
<td>
<span style=" text-decoration: underline; font-weight:bold; color:#0000FF">有变价</span>
</td>
像上面这种时取出“有变价”
没变价时显示为:
<td>
<span class=salePrice>2300.0</span><br>
      <span class=balPrice> 2000.0</span><br>
</td>
像上面这种时取出"2300.0"和"2000.0"

解决方案 »

  1.   

    @"(?i)(?<=\>)[^<>]*(?=</span>)"
      

  2.   


      string sSource = @"<td> 
    <span class=salePrice>2300.0 </span> <br> 
          <span class=balPrice> 2000.0 </span> <br> 
    </td> ";
                MatchCollection mc = Regex.Matches(sSource, @"<span.*?>(.*?)</span>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Groups[1].Value.Trim());
                }
                Console.ReadLine();