public string GetHref(string HtmlCode)
    {
        string MatchVale = "";
        string Reg = @"(h|H)(r|R)(e|E)(f|F) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)('|""| *|>)?";
        foreach (Match m in Regex.Matches(HtmlCode, Reg))
        {            MatchVale += (m.Value).ToLower().Replace("href=", "").Replace("\"", "").Trim() + "<br />";        }
        return MatchVale;
    }以上是提取网页超链接的正则,现在无法处理以下JS链接的特殊情况,那位麻烦给看下改下呀?
<A href=# onClick="javascript:window.open('zb_prev.asp?id=2008723163932160','', 'toolbars=0, scrollbars=yes, location=0, statusbars=0, menubars=0, resizable=1,width=750, height=570, left = 150, top = 100')">&nbsp;&nbsp;郑州:体育馆楼 </A>最好是改成兼容最上面的那个,实在不行单独写一个也可以

解决方案 »

  1.   

    你正则表达式处理<a href="zb_prev.asp"></a>这样的链接window.open *\( *'\w((\w|\\|\/|\.|:|-|_|\?|=)+) *'
    上面这个表达式取出window.open('zb_prev.asp?id=2008723163932160'这部分,你仍然需要替代window.open 左括号 和两个单引号,需要三次操作,最后去空格,跟你的操作一样,主要避免空格的影响
      

  2.   

    两个正则表达式都没有匹配&有可能出现href='index.asp?id=5&ip=202'
      

  3.   

    请问你<A href=# onClick="javascript:window.open('zb_prev.asp?id=2008723163932160','', 'toolbars=0, scrollbars=yes, location=0, statusbars=0, menubars=0, resizable=1,width=750, height=570, left = 150, top = 100')">&nbsp;&nbsp;郑州:体育馆楼 </A>这段语句你想匹配出的最终结果是什么?
      

  4.   

    字符串分离出:'zb_prev.asp?id=2008723163932160'
    再用
    GetHref(string HtmlCode)
      

  5.   

    string result = "";
     string src = "<a href=\"http://www.csdn/p1.pdf\">PDF</a><a href='abc.jpef'>aaa </a>";
                src += "<A href=# onClick=\"javascript:window.open('zb_prev.asp?id=2008723163932160','', 'toolbars=0, scrollbars=yes, location=0, statusbars=0, menubars=0, resizable=1,width=750, height=570, left = 150, top = 100')\">&nbsp;&nbsp;郑州:体育馆楼 </A>";
                src += "<a href=\"http://www.csdn/p2.pdf\">PDF</a><a href=\"http://www.csdn/p3.pdf\">PDF</a>";
      MatchCollection mc = Regex.Matches(src, @"(?<=(href=)|(window\.open\())['""]([^'""]+)['""]", RegexOptions.IgnoreCase);
                foreach (Match m in mc)
                {
                    result += m.Value + "\r\n";
                }