日期:2014-05-18  浏览次数:20544 次

正则表达式 如何嵌套查询 用C#
 src= "/attach/images/

  src= "/attach/images/

<IMG   height=154   src= "/attach/images/2004-02-2745673/2.27-2.jpg "   width=200   border=0>
  <IMG   height=154   src= "/attach/images/2004-02-2745673/2.27-3.jpg "   width=200   border=0>
  <IMG   height=154   src= "/attach/images/2004-02-2745673/2.27-4.jpg "   width=200   border=0>


我想把上面所有 <img的标签里的   src地址里
的src= "/attach/images替换   成我想要的东西。用C#正则如何做到

------解决方案--------------------
不是太明白楼主要的结果,这样试下吧

string yourStr = ............;
string result = Regex.Replace(yourStr, @ "( <img[^> ]*)src= " "/attach/images([^> ]*> ) ", "$1替换结果$2 ", RegexOptions.IgnoreCase);

------解决方案--------------------
string str = @ "&nbsp;src= " "/attach/images/ &nbsp;&nbsp;src= " "/attach/images/ <IMG height=154 src= " "/attach/images/2004-02-2745673/2.27-2.jpg " " width=200 border=0> <IMG height=154 src= " "/attach/images/2004-02-2745673/2.27-3.jpg " " width=200 border=0> <IMG height=154 src= " "/attach/images/2004-02-2745673/2.27-4.jpg " " width=200 border=0> "; str = System.Text.RegularExpressions.Regex.Replace(str,@ "( <img[^> ]*?src=) " "/attach/images ", "$1****** ",System.Text.RegularExpressions.RegexOptions.IgnoreCase); Response.Write(Server.HtmlEncode(str));