Capture data from string using regular expression

Comments

1 comment

  • Leon Brocard

    [quote="Suraj_Dalvi, post:1, topic:1066"] image/png [/quote]

    Hi Suraj,

    Something like the following should extract the png part of image/png:

    ```vcl if (req.http.Content-Type ~ "^(.+)/(.+)$") { set req.http.type = re.group.2; }

    if req.http.Content-Type is "image/png"

    then req.http.type is now "png"

    ```

    We cover capturing matches in more detail (with examples) in our documentation: https://docs.fastly.com/guides/vcl/vcl-regular-expression-cheat-sheet

    Regards, Léon

Please sign in to leave a comment.