In varnish, all regexes are compiled when the configurations are first loaded, and therefore must be static strings.
One way to work around this limitation is to use regsub
call to extract the portion of the URL you are interested in, then test for equality:
set req.http.X-SLUG = regsub(req.http.cookie, ".*user_slug=([^;]+).*", "\1");
set req.http.X-TMP-URL = regsub(req.url, "^/(.*)$", "\1");
if (req.http.X-SLUG == req.http.X-TMP-URL) {
....
}
remove req.http.X-TMP-URL;
Note, in the above example I removed a ;
from the X-SLUG regex. This allows the regex to work even when user_slug is the last cookie in the list.