我正在尝试为路径/s/<4-6 character string here>设置一个正则表达式,其中我将4-6字符串捕获为$1。
我尝试使用以下两个条目,但都失败了
location ~ ^/s/([0-9a-zA-Z]){4,6}+$ { ...
location ~ ^/s/([0-9a-zA-Z]{4,6})+$ { ...第一种是“未知指令”,第二种是“pcre_compile() failed:缺失”。
编辑
该地点将提供下列路线:
/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等等。
发布于 2013-04-23 18:10:17
如果您想捕获4到6个字符,为什么没有在捕获括号中添加量词呢?
也许是这样的:
location ~ "^/s/([0-9a-zA-Z]{4,6})$" {...大括号用于regex和块控制,必须用引号(单引号或双引号)括起来(<- wiki nginx)。
https://stackoverflow.com/questions/16175665
复制相似问题