日期:2014-05-17  浏览次数:20479 次

html求一难点的正则
<a href="http://nn.c365.com/newhouse/h234.shtml#teambuy"
 target="_blank">我要团购</a>
<a 
href=http://nn.c365.com/newhouse/h758.shtml#teambuy target="_blank">我要团购</a>
<a href='http://nn.c365.com/newhouse/h787.shtml#teambuy' target="_blank">我要团购</a>
<a target="_blank" href="h234.shtml#teambuy">我要团购</a>
<a target="_blank" href=http://nn.c365.com/newhouse/h34.shtml#teambuy>我要团购</a>
<a target="_blank" href='http://nn.c365.com/newhouse/h4.shtml#teambuy'>我要团购</a>

<p>
&nbsp;&nbsp;&nbsp;&nbsp;<strong><a href="http://nn.zp365.com/newhouse/h2.shtml" target="_blank">中房翡翠园</a></strong>【<a href="http://nn.zp365.com/newhouse/h2.shtml" target="_blank">详情</a>&nbsp;<a href="http://nn.zp365.com/newhouse/HouseImgList.aspx?hid=2&amp;tid=0" target="_blank">户型</a>&nbsp;<a href="http://nn.zp365.com/newhouse/HouseImgGeneralList.aspx?hid=2" target="_blank">图库</a>&nbsp;<a href="http://nn.zp365.com/newhouse/otherInfo.aspx?hid=2&amp;typeInfo=Dc" target="_blank">动态</a>&nbsp;<a href="http://nn.zp365.com/newhouse/HouseMap.aspx?hid=2" target="_blank">地图</a>】&nbsp;<a href="http://nn.c365.com/newhouse/h2.shtml#teambuy">&gt;&gt;&gt;我要团购</a></p>

含有#teambuy的连接,把 target="_blank"和连接href里的内容替换成 href="javascript:;" onclick="showTeamBuy('234')"
红色的数字保留
我写的是Response.Write(Regex.Replace(s, "<a([^<>]+)href=(\"|'|).*?(\\d+)\\.shtm([^<>]+)#teambuy(\"|'|)(([^<>]+)|)>", "<a href=\"javascript:;\" onclick=\"showTeamBuy('$3')\">"));
但里面的很多连接都替换了

------解决方案--------------------
不知道你到底想问什么,写清楚点;  我觉得是不是可以考虑用js呢 
------解决方案--------------------


   protected void b3_Click(object sender, EventArgs e)
    {
        l3.Text = "";
        string[] str = new string[9];
        str[0] = "<a href=\"http://nn.c365.com/newhouse/h234.shtml#teambuy\"";
        str[1] = "<a href='http://nn.c365.com/newhouse/h787.shtml#teambuy' target=\"_blank\">";
        str[2] = "<a target=\"_blank\" href=\"h234.shtml#teambuy\">我要团购</a>\"";
        str[3] = "<a target=\"_blank\" href=http://nn.c365.com/newhouse/h34.shtml#teambuy>我要团购</a>";
        str[4] = "<a target=\"_blank\