Extracting matches in NGiNX with regex without if block
14,253
You can catch content to variable with PCRE named capture. It is well described in the official Nginx doc.

Author by
jnbdz
Updated on September 18, 2022Comments
-
jnbdz 10 months
With NGiNX I get a string that contains information that I can extract content with regex.
But the only way I found that I could do this, is with if block. Is there any another way?
The extracted value needs to be set in a variable.
-
jnbdz about 10 yearsThat's for when you use server_name. I am trying to catch the value found in a string that as nothing to do with the domain name and is found in the location block.
-
Max Kochubey about 10 yearsNo, it's not. Try such config: location ~ ^/foobar/(?<somenumbers>\d+) { return 200 "New link will be: somecoolsite.com/$somenumbers.jpeg\n"; default_type text/plain; }