Reputation: 427
What I have is this string..
/website.com/index.php/Tools/Misc/renderer
What I need to get from this is
/website.com/index.php/Tools/Misc/
I can use jQuery and/or plain javascript to get this string.
Upvotes: 0
Views: 34
Reputation: 59232
Just do this, without regex
var str = "/website.com/index.php/Tools/Misc/renderer";
var newStr = str.substr(0,str.lastIndexOf('/')+1);
console.log(newStr); // "/website.com/index.php/Tools/Misc/"
Remove +1 in second line if you don't want a trailing slash.
Upvotes: 2
Reputation: 10849
This removes the last part of your path
var st = '/website.com/index.php/Tools/Misc/renderer'.split(/\/[^/]+$/).join('/');
Upvotes: 1
Reputation: 174696
You could try the below regex to remove all the characters which are just after to the last /
symbol.
> "/website.com/index.php/Tools/Misc/renderer".replace(/[^\/]*$/g, '')
'/website.com/index.php/Tools/Misc/'
Upvotes: 1