Is there an easy way in javascript to replace the last occurrence of an '_' (underscore) in a given string?
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
2.1m questions
2.1m answers
60 comments
56.9k users