Is Possible To Get Last Path Of Regexp In Url
Is possible to get the last value in URL results in the following string: http://www.example.com/snippets/rBN6JNO/ My RegEx is matching the whole string \/.+\/ It matches:
Solution 1:
/([a-z\d]+)(\/*|)$/i
And see "$1"
Solution 2:
Try this using javaScript you can do it,
var URL_STRING = 'http://www.example.com/snippets/rBN6JNO/'
URL_STRING.split('/').slice(3)
Solution 3:
You can split your URL with /
, and then access the last object of the splited URL.
Try the following:
var url = "http://www.example.com/snippets/rBN6JNO";
var splitedUrl = url.split('/');
var lastPath = splitedUrl[splitedUrl.length - 1]; //rBN6JNO
Solution 4:
To avoid to create an array, you can do this with string methods only - using substr() and lastIndexOf():
s = s.replace(/\/$/,"");
console.log(s.substr(s.lastIndexOf("/") + 1));
Post a Comment for "Is Possible To Get Last Path Of Regexp In Url"