请教 如何写
 class="pic" href="http://product.dangdang.com/product.aspx?product_id=22923011#ddclick?
act=click&pos=22923011_0_1_q&cat=&key=9787538460131
 的正侧表达式至少 筛选 class="pic"和 product_id= 目的是筛选product_id的值HTMLjs

解决方案 »

  1.   

    你了解html吗?比如说    class="pic" mystyle="asdf\"2334"  href="http://product.dangdang.com/product.aspx?product_id=22923011#ddclick?
     act=click&pos=229230"   href="http://product.dangdang.com/product.aspx?product_id=22923011#ddclick?
     act=click&pos=229" class="pic"等等,这些都是同一个东西。而你的所谓正则,并不懂语法分析,只懂简单匹配词法。
      

  2.   

    Refer:
    http://www.cnblogs.com/insus/archive/2012/10/30/2745843.html
      

  3.   

    (?is)<a[^>]*?class="pic"[^>]*?href="[^"]*?product_id=([^"#]*?)(?=#)
    取Group[1].Value
      

  4.   

     MatchCollection mc = Regex.Matches(Search_Html_DanPin, @"(class=(pic)).*?(product_id=(\d+))");
     //Search_Html_DanPin 是我获取的HEML页面内容 
    //class=(pic)).*?(product_id=(\d+) 写的不对 请教此处应该怎么写
                string[] res = new string[mc.Count];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = "";
                }
                for (int i = 0; i < mc.Count; i++)
                {
                    res[i] = mc[i].Value.ToString();
                }
                return res;
      

  5.   

    MatchCollection mc = Regex.Matches(Search_Html_DanPin, @"(?is)<a[^>]*?class="pic"[^>]*?href="[^"]*?product_id=([^"#]*?)(?=#)");
    报错 语法错误?