My favourite way of doing this is "splitting and popping":
var str = "test_23";
alert(str.split("_").pop());
// -> 23
var str2 = "adifferenttest_153";
alert(str2.split("_").pop());
// -> 153
split() splits a string into an array of strings using a specified separator string. pop() removes the last element from an array and returns that element.
Best Answer
Docs.
For all occurrences to be discarded use:
PS: The replace function returns a new string and leaves the original string unchanged, so use the function return value after the replace() call.