Regular expression length syntax not working?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Regular expression length syntax not working?

vedranf
Hi

This is my second post. :-)

I have a regular expression in my location directive to match on a URL.

When I use:

http {
    ...
 
        location ~ ^/event/[0-9,A-Z]{16}/info$ {
            proxy_pass <a href="http://localhost:7777;">http://localhost:7777;
        }
    }
}

I don't get a match.

I have to manually repeat the [0-9,A-Z] sixteen times to get a match.
Escaping the {} doesn't work either, i.e. /[0-9,A-Z]\{16\}/info

How can I use the {} syntax correctly?

nginx-V output, below.

nginx.conf used here:
https://gist.github.com/mikquinlan/e68848bb4930725a6fdd

All help appreciated.

Thank you.

Mik


Output of nginx -V
------------------------
nginx version: nginx/1.6.2
built by clang 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.6.2
--with-http_ssl_module --with-pcre --with-ipv6
--sbin-path=/usr/local/Cellar/nginx/1.6.2/bin/nginx
--with-cc-opt='-I/usr/local/Cellar/pcre/8.35/include
-I/usr/local/Cellar/openssl/1.0.1i/include'
--with-ld-opt='-L/usr/local/Cellar/pcre/8.35/lib
-L/usr/local/Cellar/openssl/1.0.1i/lib'
--conf-path=/usr/local/etc/nginx/nginx.conf
--pid-path=/usr/local/var/run/nginx.pid
--lock-path=/usr/local/var/run/nginx.lock
--http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp
--http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp
--http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp
--http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp
--http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp
--http-log-path=/usr/local/var/log/nginx/access.log
--error-log-path=/usr/local/var/log/nginx/error.log
--with-http_gzip_static_module

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,255413,255413#msg-255413

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression length syntax not working?

Francis Daly
On Wed, Dec 10, 2014 at 09:51:11PM -0500, hyperion wrote:

Hi there,

>         location ~ ^/event/[0-9,A-Z]{16}/info$ {
>             proxy_pass <a href="http://localhost:7777;">http://localhost:7777;
>         }

> I don't get a match.


[root@monolith1 nginx]# sbin/nginx -t
nginx: [emerg] unknown directive "16}/info$" in /usr/local/nginx/conf/nginx.conf:32
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

I suspect that you also don't get the config file used at all.

> I have to manually repeat the [0-9,A-Z] sixteen times to get a match.
> Escaping the {} doesn't work either, i.e. /[0-9,A-Z]\{16\}/info
>
> How can I use the {} syntax correctly?

This page seems to describe the nginx regular expression syntax

http://nginx.org/en/docs/http/server_names.html#regex_names

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression length syntax not working?

vedranf
HI Francis

The link to the doc was exactly what I was looking for.

The regex works as expected now.

Thanks

Mik

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,255413,255442#msg-255442

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression length syntax not working?

sonpg
For those who are looking for the answer:

> A regular expression containing the characters “{” and “}” should be
quoted.

So, his location directive:
location ~ ^/event/[0-9,A-Z]{16}/info$ {
    proxy_pass <a href="http://localhost:7777;">http://localhost:7777; 
}

Should look like this in order to work:
location ~ "^/event/[0-9,A-Z]{16}/info$" {
    proxy_pass <a href="http://localhost:7777;">http://localhost:7777; 
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,255413,277974#msg-277974

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx