加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx location regex – 字符类和匹配范围

发布时间:2020-12-13 21:23:58 所属栏目:Nginx 来源:网络整理
导读:我正在尝试为路径/ s / 我将4-6个字符串捕获为$1. 我尝试使用以下两个条目,但都失败了 location ~ ^/s/([0-9a-zA-Z]){4,6}+${ ...location ~ ^/s/([0-9a-zA-Z]{4,6})+${ ... 第一个出现未知指令,第二个出现pcre_compile()失败:遗失 编辑 此位置将提供以下路

我正在尝试为路径/ s /< 4-6字符串设置正则表达式>我将4-6个字符串捕获为$1.

我尝试使用以下两个条目,但都失败了

location ~ ^/s/([0-9a-zA-Z]){4,6}+${ ...

location ~ ^/s/([0-9a-zA-Z]{4,6})+${ ...

第一个出现’未知指令’,第二个出现’pcre_compile()失败:遗失”

编辑

此位置将提供以下路线:

/s/1234 (and I would capture '1234' in $1)
/s/12345 (and I would capture '12345' in $1)
/s/123456 (and I would capture '123456' in $1)
/s/abcd (and I would capture 'abcd' in $1)
/s/abcde (and I would capture 'abcde' in $1)
/s/abcdef (and I would capture 'abcdef' in $1)
/s/a1b2c (and I would capture 'a1b2c' in $1)

此位置不提供以下路线:

/s/1
/s/12
/s/123
/s/a
/s/ab
/s/abc
/s/abc1234
/s/12345678

等等…

如果你想捕获4到6个字符,为什么你没有把量词放在捕获括号内?

也许这样的事情:

location ~ "^/s/([0-9a-zA-Z]{4,6})$" {...

在正则表达式和块控件中都使用了大括号,你必须用引号括起你的正则表达式(单引号或双引号)(< --wiki nginx)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读