function changeChar(string, position, character) { return string.replace(new RegExp("^(.{" + (position-1) + "})(.)"), "$1" + character); } alert( changeChar("Hello", 2, "j") );