'nginx map with multiple capture groups results in `[emerg] unknown "a$b" variable`
Is it possible to return multiple regex capture groups in a nginx map block?
This works fine, returning only the first capture group $a:
map $request_uri $result {
"~(?<a>.)(?<b>.*)" $a;
default $request_uri;
}
But I can’t return both capture groups as $a$b:
map $request_uri $result {
"~(?<a>.)(?<b>.*)" $a$b;
default $request_uri;
}
This causes a [emerg] unknown "a$b" variable error message when running nginx -t.
The same problem occurs if I use regular numbered regex capture groups ($1$2) instead of named capture groups.
Is there any way to do use a map to return multiple regex captures?
I'm using nginx 1.10.3.
Solution 1:[1]
I solved this thanks to @IvanShatsky. The solution is to upgrade nginx.
Versions of nginx before 1.11.0 do not support returning multiple capture groups. From the changlog:
Changes with nginx 1.11.0 24 May 2016
*) Feature: the "map" directive supports combinations of multiple
variables as resulting values.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Quinn Comendant |
