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

请问一个正则表达式的问题
目标:截取html中<span class='tpc_contend'><br>和</font></span>中间的内容


 
  private void button1_Click(object sender, EventArgs e)
  {  
  string str = "<br><span class='tpc_contend'><br> <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <font color='red'> &lt;悔恨的泪&gt; </font></span>"; //实验用str
  string strRes = "";
  Regex reg =new Regex("(?<=<span class='tpc_contend'><br>).*(?=</font></span>)");
  MatchCollection mc = reg.Matches(str);
  for (int i=1;i<mc.count+1;i++)
  {  
  strRes += reg.Matches(str)[i].ToString(); 
  }
  richTextBox1 .Text =strRes.ToString();
   
好像算法不对 求助正则达人 在线等~~

------解决方案--------------------
简单的改了一下
C# code

   string str1 = "<br><span class='tpc_contend'><br> <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <font color='red'> &lt;悔恨的泪&gt; </font></span>"; //实验用str

            Match m = Regex.Match(str1,"(?<=<span class='tpc_contend'><br>).*(?=</font></span>)");
            string strRes = m.Value;