求一替换正则表达式

macpc 2009-10-27 01:24:53

string url = @"<a disabled=""disabled"" style=""margin-right:5px;"">首页</a><a disabled=""disabled"" style=""margin-right:5px;"">上一页</a><span class=""cpb"" style=""margin-right:5px;"">1</span><a href=""WriteAndUpByftp.aspx?page=2"" class=""paginator"" style=""margin-right:5px;"">2</a><a href=""WriteAndUpByftp.aspx?page=3"" class=""paginator"" style=""margin-right:5px;"">3</a><a class=""paginator"" href=""WriteAndUpByftp.aspx?page=2"" style=""margin-right:5px;"">下一页</a><a class=""paginator"" href=""WriteAndUpByftp.aspx?page=3"" style=""margin-right:5px;"">尾页</a>
";
string pattern = @"";//正则我应怎样写?
Regex rgx = new Regex(pattern);
string a = rgx.Replace(url,"");//这里怎么写?
Response.Write(a);



我需要将所有WriteAndUpByftp.aspx?page=1 WriteAndUpByftp.aspx?page=2……等WriteAndUpByftp.aspx?page开头的替换成如aabb1.htm aabb2.htm……这样的语名,再比如:
WriteAndUpByftp.aspx?page=1 ——aabb1.htm
WriteAndUpByftp.aspx?page=2——aabb2.htm
WriteAndUpByftp.aspx?page=3——aabb3.htm
...全文
121 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gonghuaqiao 2009-10-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wszhoho 的回复:]

string pattern = "WriteAndUpByftp.aspx\\?page=(\\d+)";
Regex.Replace(url,pattern,"aabb$1.htm");

[/Quote]
这个挺好
fhjzgsy 2009-10-27
  • 打赏
  • 举报
回复

string oldUrl = HttpContext.Current.Request.RawUrl;
string pattern = @"^(.+)News(d+).html(?.*)*$";
  string replace = "$1NewsDetails.aspx?NID=$2";
if (Regex.IsMatch(oldUrl, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))
  {
    string newUrl = Regex.Replace(oldUrl, pattern, replace,
      RegexOptions.Compiled | RegexOptions.IgnoreCase);
    this.Context.RewritePath(newUrl);
  }
wszhoho 2009-10-27
  • 打赏
  • 举报
回复
string pattern = "WriteAndUpByftp.aspx\\?page=(\\d+)";
string a = Regex.Replace(url,pattern,"aabb$1.htm");

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧