There is no need for jQuery or regular expressions, assuming that the character you want to replace exists in the string
Replace last character in string
str = str.substring(0,str.length-2)+otherchar
Replace last underline in line
var pos = str.lastIndexOf('_'); str = str.substring(0,pos) + otherchar + str.substring(pos+1)
or use one of the regular expressions from the other answers
var str1 = "Replace the full stop with a questionmark." var str2 = "Replace last _ with another char other than the underscore _ near the end"
mplungjan Mar 31 '11 at 8:52 2011-03-31 08:52
source share