110,534
社区成员
发帖
与我相关
我的任务
分享
//Try it.
string str = @"<a href=""http://www.d.com""
title=""http://www.d.com"" target=""_blank"">http://www.d.com </a><a href=""http://www.g.com""
title=""http://www.g.com"" target=""_blank"">http://www.g.com </a> ";
String str1 = @"http://www.c.com";
Regex objRegex = new Regex(@"(?im)(?<=\<a[^>]+?(?:href|title)=(""|'))[^>]+?(?=\1)");
String strRt = objRegex.Replace(str, str1);
Response.Write(String.Format("Result : {0}<br />", HttpUtility.HtmlEncode(strRt)));
/*
Result : <a href="http://www.c.com" title="http://www.c.com" target="_blank">http://www.d.com </a><a href="http://www.c.com" title="http://www.c.com" target="_blank">http://www.g.com </a>
*/
string str = "<a href=\"http://www.d.h.com\" title=\"http://www.d.com\" target=\"_blank\">http://www.d.com </a>";
string repStr = "www.c.com";
string res = Regex.Replace(str, "(?<=\")[^\"]*(?=\"\\s)", repStr);
string str = "<a href=\"http://www.d.com\" title=\"http://www.d.com\" target=\"_blank\">http://www.d.com </a>";
string repStr = "c";
string res = Regex.Replace(str, "(?<=[^\"]\"http://www.)[^.com]*", repStr);
string str = "<a href=\"http://www.d.com\" title=\"http://www.d.com\" target=\"_blank\">http://www.d.com </a>";
string repStr = "http://www.c.com";
string res = Regex.Replace(str, "(?<=[^\"]\")http://www.d.com(?=\")", repStr);
string test = "<a href=\"http://www.d.com\" title=\"http://www.d.com\" target=\"_blank\">http://www.d.com </a>";
Regex reg = new Regex(@"(?<=[\s""]*)http://www.[a-z]+.[a-z]+(?=[\s""]*)");
test = reg.Replace(test, "http://www.c.com");
Response.Write(test);
Response.End();
Regex.Replace(a, @"(?<=(href=\"))[^ ]+(?=\")|(?<=(title=\"))[^ ]+(?=\")", "http://www.c.com");
tmpStr = "title="http://www.c.com" target="_blank">http://www.d.com </a> ";
Regex rgx = new Regex(@"[>]\w*[</a>]");
tmpStr = rgx.Replace(tmpStr, ">http://www.c.com</a>")
"([^"]*)"