You don’t need jQuery, just a regular expression.
This will remove the last underscore:
var str="a_b_c";
console.log( str.replace(/_([^_]*)$/, '$1') ) //a_bc
This will replace it with the contents of the variable replacement:
var str="a_b_c",
replacement="!";
console.log( str.replace(/_([^_]*)$/, replacement + '$1') ) //a_b!c