try with this
var url="http://a.long.url/can/be/here/jquery.min.js?207";
var path = url.split( "https://stackoverflow.com/" );
var stripped = "";
for ( i = 0; i < path.length-1; i++ ) {
if(i>0) stripped += "https://stackoverflow.com/";
stripped += path[i];
}
alert(stripped)
solved Extract a part from URL in Javascript [duplicate]