Regex groups for cloudinary url

  cloudinary, javascript, regex

I’m trying to capture different parts of a url while ignoring parts that sometimes comes up.

I’ve tried using and extending the regex found here with little luck. https://gist.github.com/ahmadawais/9813c44b7e51c2c3540d2165d6c6cc65

Take the example

https://res.cloudinary.com/test-site/image/upload/v1619174590/folder/path/cjtdn73cleqagpy4fqza.jpg

https://res.cloudinary.com/test-site/image/upload/ar_1:1,c_fill,f_auto,g_auto,w_700/v1619174590/folder/path/cjtdn73cleqagpy4fqza.jpg

https://res.cloudinary.com/test-site/image/facebook/fb_id

res.cloudinary.com : host
test-site : cloudname
upload/facebook: resource_type
id: v1619174590/rg/collective/media/cjtdn73cleqagpy4fqza.jpg

I need to ignore everything between /upload/ and /v, I’ve accomplished this using //upload/.*?b(?=v1)/ , but it doesn’t account for if the resource type is facebook and there is no /v123

Source: Ask Javascript Questions

LEAVE A COMMENT