string str = "<div class=\"op_mp_r\"> <span>手机号码&quot;1821000&quot;</span> <span>&nbsp;北京&nbsp;&nbsp;中国移动 GSM</span> </div> ";
我想找到“北京”和“中国移动”

解决方案 »

  1.   

    为什么要用正则啊,用jquery多简单啊。。
      

  2.   

    仅限制与本例
    string str = "<div class=\"op_mp_r\"> <span>手机号码&quot;1821000&quot;</span> <span>&nbsp;北京&nbsp;&nbsp;中国移动 GSM</span> </div> ";
                    Regex _reg = new Regex(@"(?i)(?<=</span>\s*?<span>).*?([\u4e00-\u9fa5]+).*?([\u4e00-\u9fa5]+).*?(?=</span>\s*?</div>)");
                    Match m=_reg.Match(str);
                    string s = m.Groups[1].Value;//北京
                    string t = m.Groups[2].Value;//中国移动
      

  3.   


    你这样写我都编译不过呢。另外能不能把<div class=\""op_mp_r"\">也加上呀,这个很重要呀。
      

  4.   

    string str = "<div class=\"op_mp_r\"> <span>手机号码&quot;1821000&quot;</span> <span>&nbsp;北京&nbsp;&nbsp;中国移动 GSM</span> </div> ";
                    Regex _reg = new Regex(@"(?i)(?<=<div[^>]*?class=(['""]?)op_mp_r[^>]*?>\s*?<span>.*?</span>\s*?<span>).*?([\u4e00-\u9fa5]+).*?([\u4e00-\u9fa5]+).*?(?=</span>\s*?</div>)");
                    Match m=_reg.Match(str);
                    string s = m.Groups[2].Value;//北京
                    string t = m.Groups[3].Value;//中国移动