function replaceChar(string, position, newValue){ return string.replace( new RegExp( "(.{" + position + "}).(.+)", "m" ) , "$1" + newValue + "$2" ); }; var test = "aac"; test = replaceChar( test, 1, "b" ); alert( test );