nginx pcre_compile error when using quantifiers

I'm having an issue with aliasing. I want to append up to the first 4 digits of the file as part of the directory. (like '../123456.jpg'=>'../123/123456.jpg' and '../12.png'=>'../12/12.png')

Here is what I have:

location ~ ^/i/gallery2/(\d{1,4})(.*)$ {
    alias /home/web/images/gallery/$1/$1$2;
}

This is the error I get:

nginx: [emerg] pcre_compile() failed: missing ) in "^/i/gallery2/(\d"

Anyone have any ideas how to get this to work? It looks like it has a problem with the "{1,4}" Is there another way to do want I want?


Solution 1:

It figures you're starting the contents of the location block. It figures wrong.

Wrap it in quotes:

location ~ "^/i/gallery2/(\d{1,4})(.*)$" {