JSFiddle - React, Tailwind, and code Playground

JavaScript

var re = /\//g,
    str = "/blog/some-blog-post-slug/whatever/anything";  //You can try out all the cases you mentioned in the question . 
var arr = [];
while ((match = re.exec(str)) != null) {
arr.push(match.index);
    console.log("match found at " + match.index);
}
console.log(arr)
if(arr.length >= 3){
    var str = str.substring(arr[1] + 1, arr[2]);
    document.write(str);
    console.log(str);
}
else{
    var str = str.substring(arr[1]);
    document.write(str);	
		
}