Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Your example works for me with nginx 1.1.19 on Ubuntu 12.04. –  mgorven Feb 26 '13 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 –  Robin Winslow Feb 26 '13 at 16:07
    
Yup, I copy/pasted your example into my config. –  mgorven Feb 26 '13 at 16:43
add comment

1 Answer

up vote 3 down vote accepted

(?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.

share|improve this answer
    
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) –  Robin Winslow Feb 26 '13 at 14:19
    
I've updated the documentation: wiki.nginx.org/HttpMapModule –  Robin Winslow Feb 26 '13 at 16:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.