另一个正则表达式 - 如何识别查询字符串

发布于 2025-01-02 01:29:43 字数 1692 浏览 3 评论 0原文

我正在使用 urlrewriting.net 进行 url 重写。我需要一些关于正则表达式的帮助(我仍然没有得到......)。

我想匹配

  • www.mysite.com/restaurant ->匹配并返回 “餐厅
  • www.mysite.com/restaurant?page=1 ->匹配和 返回“restaurant
  • www.mysite.com/restaurant?[SOME_RANDOM_QUERYSTRING] ->匹配 并返回“restaurant
  • www.mysite.com/seattle/restaurant ->匹配并返回“seattle”并且 “餐厅
  • www.mysite.com/seattle/restaurant?page=1 ->匹配和 返回“seattle”和“restaurant
  • www.mysite.com/seattle/restaurant?[SOME_RANDOM_QUERYSTRING] ->匹配 并返回“seattle”和“restaurant
  • www.mysite.com/seattle/restaurant-michelangelo ->不要赶上
  • www.mysite.com/seattle/restaurant/sushi ->匹配并返回“seattle” 和“餐厅”和“寿司
  • www.mysite.com/seattle/restaurant/sushi?page=1 ->匹配并返回 “西雅图”和“餐厅”和“寿司
  • www.mysite.com/seattle/restaurant/sushi?[SOME_RANDOM_QUERYSTRING] -> 匹配并返回“seattle”和“restaurant”和“sushi
  • www.mysite.com/seattle/restaurant-michelangelo< /代码> ->不明白

要点是我需要 url 的目录部分而不是查询字符串部分。问题是,我可以从我的网络分析工具中看到,人们通过两个词进行搜索。他们都搜索城市(西雅图)+类别(餐厅),例如。 “西雅图餐厅”以及城市(西雅图)+餐厅名称(餐厅-米开朗基罗),例如。 “西雅图餐厅-米开朗基罗”。从结构的角度来看,这当然是一团糟,因为这不是一个层次结构。在理想的世界中,层次结构将是城市 ->类别->餐厅。但我仍然想在我的网址结构中容纳这种搜索行为。同时我还有一个页面列出了该国所有的餐馆。

我希望获得有关如何创建正则表达式以及创建它们的最有效方法的帮助,因为我猜它们可能会变得相当昂贵。

谢谢

托马斯

I am using urlrewriting.net for my urlrewriting. I need some help on the regex (which I still don't get....).

I would like to match

  • www.mysite.com/restaurant -> match and return
    "restaurant"
  • www.mysite.com/restaurant?page=1 -> match and
    return "restaurant"
  • www.mysite.com/restaurant?[SOME_RANDOM_QUERYSTRING] -> match
    and return "restaurant"
  • www.mysite.com/seattle/restaurant -> match and return "seattle" and
    "restaurant"
  • www.mysite.com/seattle/restaurant?page=1 -> match and
    return "seattle" and "restaurant"
  • www.mysite.com/seattle/restaurant?[SOME_RANDOM_QUERYSTRING] -> match
    and return "seattle" and "restaurant"
  • www.mysite.com/seattle/restaurant-michelangelo -> don't catch
  • www.mysite.com/seattle/restaurant/sushi -> match and return "seattle"
    and "restaurant" and "sushi"
  • www.mysite.com/seattle/restaurant/sushi?page=1 -> match and return
    "seattle" and "restaurant" and "sushi"
  • www.mysite.com/seattle/restaurant/sushi?[SOME_RANDOM_QUERYSTRING] ->
    match and return "seattle" and "restaurant" and "sushi"
  • www.mysite.com/seattle/restaurant-michelangelo -> don't catch

The point being I need the directory-parts of the url and not the querystring-parts. The thing is that I can see from my web analytics tool, that people search by two words. They both search for the city (seattle) + category (restaurant) eg. "seattle restaurant" and also for the city (seattle) + the name of the restaurant (restaurant-michelangelo) eg. "seattle restaurant-michelangelo". From a structural point of view, this is of course a mess, since this is not a hierarchy. In the ideal world the hierarchy would be city -> category -> restaurant. but I would still like to accommodate this search behavior in my url-structure. At the same time I also have a page listing all restaurants in the country.

I would like help on how to create the regexes as well as the most efficient way of creating them since I guess they could become quite expensive.

thanks

Thomas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫七 2025-01-09 01:29:43

使用这个:

/\/[A-Za-z0-9]{1,}(?:\/|$|\?)/

匹配/字母数字 1-无穷大,然后斜杠、行尾或问号

use this:

/\/[A-Za-z0-9]{1,}(?:\/|$|\?)/

Matches / Alphanumerics 1-infininity then slash, End of Line, or Question mark

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文