Search code examples
regexvarnishregsub

capture value to the left of querystring using regsub


Here is a sample URL:

https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30

What I want from this is just:

/productimages/1679/T716AP1_lg

My current code is:

regsub(req.url, "^/(.*)\.(.*)$", "\1")

Which works great until there are multiple query string parameters link in my example above, seems the & is causing me problems.


Solution

  • Try capturing non-dots/questions instead:

    regsub(req.url, "^http://.*?/([^?.]+).*$", "\1")