Remove last element from url

javascript, jquery

Solution

$('span').attr('st_url', function(i, url) {
    var str = url.substr(url.lastIndexOf('/') + 1) + '$';
    return url.replace( new RegExp(str), '' );
});

DEMO

Problem

I need to remove the last part of the url from a span.. I have ``` <span st_url="http://localhost:8888/careers/php-web-developer-2" st_title="PHP Web Developer 2" class="st_facebook_large" displaytext="facebook" st_processed="yes"></span></span> ``` And I need to take the `st_url` and remove the `php-web-developer-2` from it so it is just `http://localhost:8888/careers/`. But I am not sure how to do that. `php-web-developer-2` will not always be that but it won't have any `/` in it. It will always be a `-` separated string. Any Help!!??

Original source