日期:2014-05-17 浏览次数:20570 次
string str = @"<p><img data-url=""/b.jpg"" src=""/_images/pixel.gif""/><img src=""/_images/pixel.gif""/></p>"; Regex reg = new Regex(@"(?is)(?<=<img\b[^>]*?)data-url=(['""\s]?)([^'""]*?)\1[^>]*?(src=)(['""\s]?)([^""']*?)\4(?=[^>]*/>)"); str = reg.Replace(str, @"data-url=$1$2$1 $3$4$2$4"); /* <p><img data-url="/b.jpg" src="/b.jpg"/><img src="/_images/pixel.gif"/></p> */
------解决方案--------------------
yourhtml=Regex.Relace(yourhtml,@"(?i)(<img\b[^>]*?data-url=(['""]?)([^'""]+)\2[^>]*?src=(['"]?))[^'"]+(\4[^>]*?>)","$1$3$5");