当前位置: 代码迷 >> ASP.NET >> 如何用正则找到html内的标签的值,多谢
  详细解决方案

如何用正则找到html内的标签的值,多谢

热度:1542   发布时间:2013-02-25 00:00:00.0
怎么用正则找到html内的标签的值,谢谢!
string str = "<div class=\"op_mp_r\"> <span>手机号码&quot;1821000&quot;</span> <span>&nbsp;北京&nbsp;&nbsp;中国移动 GSM</span> </div> ";
我想找到“北京”和“中国移动”

------解决方案--------------------------------------------------------
C# code
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;//中国移动
  相关解决方案