I have a url in the formathttp://localhost:8080/testURL/location/#/old/Ds~1016,
The value 1016 will change based on the page selected.. is it possible in javascript to get the number 1016 part from url(based on page selected)???
Ive tried the function
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if (results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
You could also try it this way
that should give you
"1016"Although the following would be better
to make sure it is the last “/” element you are splitting
UPDATE
I always prefer using split() if it is for a single condition because the code is more understandable even though regex give better performance in the longer run. You can check the performance of regex vs split here