Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: – Robin Winslow Feb 26 '13 at 16:07
Yup, I copy/pasted your example into my config. – mgorven Feb 26 '13 at 16:43
up vote 5 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: – Robin Winslow Feb 26 '13 at 16:06

Your Answer


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.