文本:<SD>
<POPULARITY URL="pconline.com.cn/" TEXT="298"/>
<REACH RANK="306"/>正则: <POPULARITY[^(/>)]*TEXT=/"(\d+)/"/>
 
匹配不到298,大家帮帮忙,看问题出在哪里,谢谢

解决方案 »

  1.   


        string tempStr = @"<POPULARITY URL=""pconline.com.cn/"" TEXT=""298""/>";
                string pattern = @"<POPULARITY[^>]*TEXT=""(?<text>[^""]*)""/>";
                MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.Singleline);
                for (int i = 0; i < mc.Count; i++)
                {
                    string text = mc[i].Groups["text"].Value;//得到298
                    this.textBox1.Text += text + "\r\n";            }
      

  2.   

     string tempStr = @"<POPULARITY URL=""pconline.com.cn/"" TEXT=""298""/>";
                string pattern = @"<POPULARITY[^>]*TEXT=""(\d+)\""/>";
                string outPut = Regex.Replace(tempStr, pattern,"$1");
    outPut就是298你的正则"不对
      

  3.   


    string tempStr = @"<POPULARITY URL=""pconline.com.cn/"" TEXT=""298""/>";
                string pattern = @"<POPULARITY[^>]*TEXT=""(\d+)""/>";
                string outPut = Regex.Replace(tempStr, pattern,"$1");应该是这样