62,041
社区成员
发帖
与我相关
我的任务
分享
string con=@"<P><IMG height=360 src="/ewebeditor/uploadfile/634479854581093750.jpg" width=550 border=0></P>
<P> </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> </P>
<P> </P>";
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,"新的字符串");
}
string con = @"<P><IMG height=360 src=""/ewebeditor/uploadfile/634479854581093750.jpg"" width=550 border=0></P>
<P> </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> </P>
<P> </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"/>
*/