I have the following code to get a string and alert it after removing only the last number. Currently I have the following code. But here, remove all the numbers in the string including numbers where at the middle of the string. But I need to remove only the numbers where at the end of the string.
Ex - String = "ABC_1_XY_20"
alert -> "ABC_1_XY_"
I need to keep "1" But now I lost it as well. How can I fix this?
$("button").on("click", function(){
var st = "ABC_1_XY_20".replace(/[\d\.]/g ,'');
alert(st);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Click</button>