62,041
社区成员
发帖
与我相关
我的任务
分享
/*
结果:
"http://www.znpx.net/Default.aspxID=1&year=2011&type=3"
http://www.znpx.net/Default.aspx?ID=1&year=2011
*/
string str = "\"http://www.znpx.net/Default.aspx?ID=1&year=2000&type=3\"";
string str1 = "http://www.znpx.net/Default.aspx?ID=1&year=2000";
string result = Regex.Replace(str, @"(?is)(?<=&year=)[^&]*", "2011");
string result1 = Regex.Replace(str1, @"(?is)(?<=&year=)[^&]*", "2011");
Response.Write(result);
Response.Write("<br/>");
Response.Write(result1);
string str = "\"http://www.znpx.net/Default.aspx?ID=1&year=2000&type=3\"";
string str1 = "http://www.znpx.net/Default.aspx?ID=1&year=2000";
string str2 = "http://www.znpx.net/Default.aspx?year=2000";
string result = Regex.Replace(str, @"(?is)(?<=[&?]year=)[^&]*", "2011");
string result1 = Regex.Replace(str1, @"(?is)(?<=[&?]year=)[^&]*", "2011");
string result2 = Regex.Replace(str2, @"(?is)(?<=[&?]year=)[^&]*", "2011");
Response.Write(result);
Response.Write("<br/>");
Response.Write(result1);
Response.Write("<br/>");
Response.Write(result2);
/*
结果
"http://www.znpx.net/Default.aspx?ID=1&year=2011&type=3"
http://www.znpx.net/Default.aspx?ID=1&year=2011
http://www.znpx.net/Default.aspx?year=2011
*/
Regex re=new Regex("&year=[\d]{0,4}");