其一:
........
<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标签里的不换
........
<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标签里的不换
string result = Regex.Replace(yourStr, @">[^<>]*(?:<|$)|^[^<>]*", delegate(Match m) { return m.Value.Replace("姚明", @"<a href=""aa.asp?name=姚明"">姚明</a>"); }, RegexOptions.IgnoreCase);