VCL using local variable in regular expression

Comments

2 comments

  • Andrew Betts

    Hi Mathieu,

    Sadly not. I'd love to say that we support dynamic regexs but unfortunately they have to be string literals. In the case of this particular pattern, you're just testing for membership of a set, which I would recommend that you do with a table. You can do that like this:

    ```

    Outside of any subroutine / or in an 'init' snippet

    table countries { "BE": "Belgium", "FR": "France", "NL": "Netherlands" }

    In vcl_recv

    if (table.lookup(countries, client.geo.country_code)) { # do stuff } ```

    You can of course use the table.lookup function repeatedly to reference the same country list.

  • messenjer

    Great !

    Thanks Andrew !

Please sign in to leave a comment.