Variable interpolation in a regex.

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

Variable interpolation in a regex.

Harish Sundararaj
Hello All,

I have a map block:

        map $http_cookie $myVal {
                "~adq_cnv(\d+)=($cmpid[^;]+#(?P<DC>\w{2}))(?:;|$)" $DC;
                default "XYZ";
        }

The $cmpid used in the left side of a map is to be interpolated from a
location block :

       location ~ ^/cnv/(\d+)/ {
                 set $cmpid  $1;
                  ...
       }

But that is not working. I tried different variations like : ${cmpid},
\$cmpid . But to no luck.

Any help would be appreciated.

Thanks
Harish

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

Re: Variable interpolation in a regex.

Valentin V. Bartenev-2
On Tuesday 04 September 2012 23:55:07 Harish Sundararaj wrote:
> Hello All,
>
> I have a map block:
>
>         map $http_cookie $myVal {
>                 "~adq_cnv(\d+)=($cmpid[^;]+#(?P<DC>\w{2}))(?:;|$)" $DC;
>                 default "XYZ";
>         }
>
[...]
>
> But that is not working. I tried different variations like : ${cmpid},
> \$cmpid . But to no luck.
>
> Any help would be appreciated.

Regular expressions in config file are compiled at the configuration phase, so
you can't use variables there.

 wbr, Valentin V. Bartenev

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

Re: Variable interpolation in a regex.

Harish Sundararaj
Hi Valentin,
Thanks. Is there any way to achieve the same thing through some other
means, even if it takes a hit on the performance ?

Thanks
Harish

On Wed, Sep 5, 2012 at 1:33 AM, Valentin V. Bartenev <[hidden email]> wrote:

> On Tuesday 04 September 2012 23:55:07 Harish Sundararaj wrote:
>> Hello All,
>>
>> I have a map block:
>>
>>         map $http_cookie $myVal {
>>                 "~adq_cnv(\d+)=($cmpid[^;]+#(?P<DC>\w{2}))(?:;|$)" $DC;
>>                 default "XYZ";
>>         }
>>
> [...]
>>
>> But that is not working. I tried different variations like : ${cmpid},
>> \$cmpid . But to no luck.
>>
>> Any help would be appreciated.
>
> Regular expressions in config file are compiled at the configuration phase, so
> you can't use variables there.
>
>  wbr, Valentin V. Bartenev
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx

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

Re: Variable interpolation in a regex.

zakirenish
Hi

Is it still true in 2020 ?

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

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