Reputation: 28248
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.
Upvotes: 1
Views: 244
Reputation: 15000
^https:\/\/[^\/]+\/([^.]*)\.jpg
This expression will do the following:
Live Demo
https://regex101.com/r/nZ7eX7/1
Sample text
https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30
Sample Matches
productimages/1679/T716AP1_lg
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
https: 'https:'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
[^\/]+ any character except: '\/' (1 or more
times (matching the most amount possible))
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[^.]* any character except: '.' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
\.jpg '.jpg'
----------------------------------------------------------------------
Upvotes: 1
Reputation: 425033
Try capturing non-dots/questions instead:
regsub(req.url, "^http://.*?/([^?.]+).*$", "\1")
Upvotes: 2