nginx位置正则expression式 – 字符类和匹配范围

我想设置一个正则expression式的path/s/<4-6 character string here>/s/<4-6 character string here>哪里捕获4-6字符的string为$ 1。

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

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

第一个出现“未知指令”,第二个出现“pcre_compile()失败:缺less)'

编辑

以下路线将由这个位置服务:

 /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)