gpt4 book ai didi

正则表达式 : get the two letters after the slash or after the last dot

转载 作者:行者123 更新时间:2023-12-04 02:28:42 25 4
gpt4 key购买 nike

我想使用正则表达式获取一个国家的 ISO 代码(两个字母)

例如,对于国家爱尔兰,ISO 代码是ie。 ISO 代码可以在斜杠 / 之后或 last 之后找到。

这是我的RewriteRule:

RewriteRule ^gallery/country(?:/[^/]*([a-zA-Z-9]{2}))?/?$ gallery/gallery.php?country=$1 [L,QSA]

这里有一些有效的 url...如果可用,我想选择 ISO 代码:

画廊/国家

画廊/国家/

画廊/国家/ie

画廊/国家/ie/

画廊/国家/爱尔兰

画廊/国家/爱尔兰/

gallery/country/ireland-love.

gallery/country/ireland-love./

gallery/country/ireland.69-love./

我已经尝试调整我在所有 seo url 中使用的模板公式,但我在使用这个公式时遇到了困难。这是我到目前为止所做的。

^gallery/country(?:/[^/]*([a-zA-Z-9]{2}))?/?$

https://regex101.com/r/88azeh/6

最佳答案

能否根据您显示的示例尝试以下操作。在引用组中捕获 . 之后的所有内容,并在此处重写时使用它。请确保在测试任何 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule \.([a-zA-Z]+){2}/?$ gallery/gallery.php?country=$1 [L]


上面不会检查 URI 的条件,要使其更具体到画廊,请尝试遵循。

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^gallery/country.*\.([a-zA-Z]+){2}/?$ gallery/gallery.php?country=$1 [L]

关于正则表达式 : get the two letters after the slash or after the last dot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65631786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com