11

/s/<4-6 character string here>4 ~ 6 文字の文字列を $1 としてキャプチャするパスの正規表現をセットアップしようとしています。

次の2つのエントリを使用してみましたが、両方とも失敗します

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

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

最初のものは「不明なディレクティブ」であり、2番目のものは「pcre_compile() failed: missing )」です。

編集

次のルートは、この場所によって提供されます。

/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

1 に答える 1

36

4 から 6 文字をキャプチャしたい場合、キャプチャ括弧内に量指定子を入れないのはなぜですか?

おそらくそのようなもの:

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

中括弧は正規表現とブロック制御の両方で使用されます。正規表現を引用符 (一重または二重) で囲む必要があります (<-- wiki nginx)

于 2013-04-23T18:10:17.410 に答える