【问题标题】:Convert URLs into Regular Expression将 URL 转换为正则表达式
【发布时间】:2012-02-19 18:20:28
【问题描述】:

我在 asp.net 中使用 Intelligencia.UrlRewriter.dll 进行 url 重写,但我不知道正则表达式。有没有人可以帮我把这些网址转换成正则表达式。

http://localhost:50788/catalog.aspx?VendorID=1&CategoryID=1

VendorID 和 CategoryID 都可以更改。

http://localhost:50788/Product.aspx?ProductID=1

同样可以更改 ProductID。 我实际上想在 web.confg 文件中为这些查询字符串编写正则表达式,例如

<!-- Rewrite department pages -->
    <rewrite url="/Index" to="~/Default.aspx" />

最后一件事,除此之外还有什么最好的 url-rewriter 吗?

【问题讨论】:

  • “将 URL 转换为正则表达式”是什么意思?也许您应该阅读一下什么是正则表达式?
  • 我的意思是,我需要可以支持编写的 URL 的正则表达式(例如上面的)。

标签: c# asp.net regex


【解决方案1】:

您的问题非常不清楚,正如其他人所指出的那样。这是你想要做的吗?

new Regex(@"http://localhost:50788/catalog\.aspx\?VendorID=\d+&CategoryID=\d+");

new Regex(@"http://localhost:50788/Product\.aspx\?ProductID=\d+");

【讨论】:

  • 我实际上是在尝试在 web.confg 文件中编写正则表达式,例如
猜你喜欢
  • 1970-01-01
  • 2010-11-06
  • 1970-01-01
  • 1970-01-01
  • 2011-10-02
  • 2016-04-02
  • 1970-01-01
  • 2019-05-11
  • 2014-11-08
相关资源
最近更新 更多