求怎么用正则匹配出img标签,并去掉img标签中除了src和border外的所有属性,并给img标签加上超链接
string con=@"<P><IMG height=360 src="/ewebeditor/uploadfile/634479854581093750.jpg" width=550 border=0></P>
<P>&nbsp;</P>
<P><IMG style="BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: black; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: black; BORDER-TOP-COLOR: black; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: black" alt=点击查看原图 src="http://hiphotos.baidu.com/mingyueshangxi/pic/item/6c291df7478dd28c7831aa1d.jpg" border=1></P>
<P><IMG src="/ewebeditor/uploadfile/20110803162636001.gif" border=0><BR>&nbsp;</P>
<P>&nbsp;</P>";

解决方案 »

  1.   

                string con = @"<P><IMG height=360 src=""/ewebeditor/uploadfile/634479854581093750.jpg"" width=550 border=0></P>
    <P>&nbsp;</P>
    <P><IMG style=""BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: black; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: black; BORDER-TOP-COLOR: black; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: black"" alt=点击查看原图 src=""http://hiphotos.baidu.com/mingyueshangxi/pic/item/6c291df7478dd28c7831aa1d.jpg"" border=1></P>
    <P><IMG src=""/ewebeditor/uploadfile/20110803162636001.gif"" border=0><BR>&nbsp;</P>
    <P>&nbsp;</P>";
                string result = Regex.Replace(con, @"(?is)<(?!img)[^>]*?>", "");
                result = Regex.Replace(result, @"(?is)<img[^>]*?src=((['""\s]?)[^'""\s]+?\2)[^>]*?border=(([^'""\s]?)[^'""\s]+?\4)[^>]*?>", "<img src=\"$1\" border=\"$3\"/>");
                Response.Write(result);
                /*
    <img src=""/ewebeditor/uploadfile/634479854581093750.jpg"" border="0"/>
    <img src=""http://hiphotos.baidu.com/mingyueshangxi/pic/item/6c291df7478dd28c7831aa1d.jpg"" border="1"/>
    <img src=""/ewebeditor/uploadfile/20110803162636001.gif"" border="0"/>
                 */
      

  2.   

    谢谢各位,自己本来解决了,没注意到,呵呵 Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?)(?<src>[^'""\s>]*)\1[^>]*>", RegexOptions.IgnoreCase);
                MatchCollection mc = reg.Matches(con);
                foreach (Match ma in mc)
                {
                   string c=ma.Value;
                   con=con.replace(c,"新的字符串");
                }