我想提取一个网页上所有类似这样的超链接地址,只有products_id的参数是可变的数字,请问这样的正则表达式该怎么写?
<a href="http://bd238.com/product_info.php?products_id=3556">xxxxx</a>

解决方案 »

  1.   

    string pattern=@"(?i)<a[^>]*?href=[""']?http://bd238\.com/product_info\.php?products_id=\d+[""']?[^>]*>[^<]*</a>";
      

  2.   

    (?is)<a.*?products_id=.*?</a>
      

  3.   

    Regex RegUrl = new Regex("<a href.*bd238.*products_id=.*</a> ", RegexOptions.ExplicitCapture | RegexOptions.Multiline | RegexOptions.IgnoreCase);
    MatchCollection mCollection = Regs.RegUrlPostNext.Matches(页面源码);
    string WebUrl ;
    foreach (Match match in mCollection)
    {
        WebUrl = match.ToString();
        WebUrl = WebUrl.Substring(WebUrl.LastIndexOf("href=\"") + 6);
        WebUrl = WebUrl.Substring(0, WebUrl.LastIndexOf("</a>") - 7).Trim();
    }
      

  4.   


    <a[\s\S]+?href\s*=\s*(['"])?(http:\/\/bd238\.com\/product_info\.php\?products_id\s*=\s*([^>\s\n]+))\1