其一:
........
<a href="http://www.abc.com">http://www.abc.com</a>
........
想把第一个http://www.abc.com换成exc?url=http://www.abc.com
第二个http://www.abc.com换成1(也就是数字)
简单方法
其二:
<html>.................
姚明<img src="a.jpg" alt=姚明>
................</html>
想把“姚明”换成<a href="aa.asp?name=姚明">姚明</a>
但img标签里的不换

解决方案 »

  1.   

    其一:string result = Regex.Replace(yourStr, @"<a\s+href=""([^""]+)""\s*>([^<]*)</a>", @"<a href=""exc?url=$1"">1</a>", RegexOptions.IgnoreCase);其二:正则委托典型应用
    string result = Regex.Replace(yourStr, @">[^<>]*(?:<|$)|^[^<>]*", delegate(Match m) { return m.Value.Replace("姚明", @"<a href=""aa.asp?name=姚明"">姚明</a>"); }, RegexOptions.IgnoreCase);