Welcome! Log In Create A New Profile

Advanced

Can I use variable in regular expression?

Posted by pdh0710 
Can I use variable in regular expression?
January 07, 2021 02:07AM
(Please excuse my English)

I'm writing a Nginx configuration file using 'if' statement.
Below is a part of the configuration file and it works well.

---
set $destination $http_destination;
set $scheme_host "$scheme://$host"; # $scheme_host = "https://your.host.com"
.......
.......
if ($destination ~ ^https://your.host.com/(.*)$) {
set $temp $1;
}
---

However, when I changed the above 'if' clause like below, but it did not work.
It seems that variables cannot be used in the regular expression.

---
if ($destination ~ ^\$scheme_host/(.*)$) {
set $temp $1;
}
---

How can I use variables in the regular expression?
Or write configuration works the same way?



Edited 1 time(s). Last edit at 01/07/2021 02:12AM by pdh0710.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 42
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready