Using capture groups in regexp replace


#1

I need to replace url like this:
/some/prefix/url
/url/secret-suffix

I’m doing it now with 2 separate rules:

  1. regexp replace “^/some/prefix” with “”
  2. append “/secret-suffix”

What I’d do if groups were supported is:
Regex: "^/some/prefix/(.+)$"
Substitution: “/$1/secret-suffix”

Is it possible?
I read vcl-regular-expression-cheat-sheet guide but it’s talking about pure VCL, not sure how to use it in UI based config.
Seems like I could use something like if(req.url ~ "^/some/prefix(/.+)$", re.group.1 "some suffix", "") in UI as constant Set mode (instead of Regex), but it looks overcomplicated.


#2

You can use \1, \2, etc. for groups in your regular expression in the UI.

So you were close with $1:

Regex: ^/some/prefix/(.+)$
Substitution: /\1/secret-suffix