2

The HttpMapModule documentation states that:

Since 1.0.4, case insensitive regular expressions can be used by prefixing the pattern with ~*.

And gives the example:

map $uri $myvalue {
    /aa                   /mapped_aa;
    ~^/aa/(?<suffix>.*)$  $suffix;
}

I updated to nginx/1.2.7 to make use of this, and naive regexes work okay, but variables don't. When I try the above syntax I get the error:

nginx: [emerg] pcre_compile() failed: unrecognized character after (?< in "^/aa/(?<suffix>.*)$" at "suffix>.*)$"

I also tried the following syntaxes, but none of them worked:

~^(.*)$  $1;
~^(.*)$  \1;

but neither of them worked either.

Does anyone know how to get variables to work in regular expressions in HttpMapModule?

4
  • 1
    Your example works for me with nginx 1.1.19 on Ubuntu 12.04.
    – mgorven
    Commented Feb 26, 2013 at 4:48
  • @mgorven that's odd. Could you confirm this is definitely true? Maybe it changed between 1.1.19 and 1.2.7. In which case I was wrong to update the documentation: wiki.nginx.org/HttpMapModule#map Commented Feb 26, 2013 at 16:07
  • Yup, I copy/pasted your example into my config.
    – mgorven
    Commented Feb 26, 2013 at 16:43
  • Works for me in 2023 on Nginx 1.25 Commented Jul 4, 2023 at 19:30

1 Answer 1

10

(?P<name>pattern) is the standard PCRE syntax for named capture-groups - the documentation is missing a P.

The "Named Subpatterns" section on Wikipedia states that (?<name>...) and (?'name'...) are valid for PCRE 7.0 onwards; presumably your version of nginx is linked against an earlier version of PCRE.

2
  • Wonderful. That is the answer. How did you know that? Where would I find PCRE documentation that explains P variables? (I did search for it) Commented Feb 26, 2013 at 14:19
  • I've updated the documentation: wiki.nginx.org/HttpMapModule Commented Feb 26, 2013 at 16:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .