正则表达式抓取字符串直到连字符

发布于 2024-11-04 20:04:24 字数 434 浏览 0 评论 0原文

我认为我遇到了问题,因为我在此表达式中使用了两个关键的正则表达式值。

RewriteRule ^([^-]*)-([^-]*)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]

当有人打字时我会被抓住

domain.com/michigan-1999-football-schedule

。它目前无法识别这个 htaccess 行的字符串,我 99% 它与正则表达式部分有关。我认为这是因为该行的 [^-] 部分。我希望这能抓取数据直到连字符,但我认为存在问题,因为两者都是正则表达式中的关键字符。

I think I'm having an issue since I'm using two key regex values in this expression.

RewriteRule ^([^-]*)-([^-]*)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]

I this to be caught when someone types

domain.com/michigan-1999-football-schedule

. It currently doesn't recognize this string with this htaccess line, and I'm 99% it has to do with the regex part. I think it's because the [^-] part of the line. I am hoping this grabs the data until a hyphen, but I think there's an issue since both are key characters in regex.

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

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

发布评论

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

评论(2

孤独患者 2024-11-11 20:04:24

这对我来说是有效的。您还有其他正在使用的规则吗?

确保您具备以下条件:

RewriteEngine on
RewriteBase / 

This is working for me as-is. Do you have other rules that you are using?

Make sure that you have the following:

RewriteEngine on
RewriteBase / 
毁梦 2024-11-11 20:04:24

我建议您使用 + 而不是 *,以防某些字段为空:

RewriteRule ^([^-]+)-([^-]+)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]

I would advise you to use + instead of *, in the case some fields would be empty:

RewriteRule ^([^-]+)-([^-]+)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文