function stringFormat(){ if(arguments.length==0) return; var string = "a{0}b{1}"; for(var i = 0 ; i < arguments.length;i++){ var re = new RegExp('\\{'+ i +'\\}','gm'); str = str.replace(re,arguments[i]); } } var name = "kitty" stringFormat("hello{0}",name)