62,046
社区成员
发帖
与我相关
我的任务
分享
string html = "<html><head><title>asp.net</title></head><body>百度<img src='b.jpg' alt='百度' 各title='百度' /></body></html>";
string href = "<a href='http://www.baidu.com/' title='百度'>百度</a>";
string html = "<html><head><title>asp.net</title></head><body>百度<img src='b.jpg' alt=\"百度\" />百度什么呀百度好强呀百度小心呀</body></html>";
string key = "百度";
string href = "<a href='http://www.baidu.com/' title='百度'>百度</a>";
Console.WriteLine(Regex.Replace(html, "([^='\"]?)("+key+")([^='\"])", "$1"+href+"$3", RegexOptions.IgnoreCase));
string html = "<html><head><title>asp.net</title></head><body>百度<img src='b.jpg' alt='百度' 各title='百度' /></body></html>";
string key = "百度";
string href = "<a href='http://www.baidu.com/' title='百度'>百度</a>";
Regex reg = new Regex(@"(^|>)[^<>]+(<|$)");
string result = reg.Replace(html, delegate(Match m) { return m.Value.Replace(key, href); });
richTextBox2.Text = result;