var ww = "texttexxttext"; var p = ww.replace("te","123"); var p2 = ww.replace(/te/g, '123'); alert(p+' :: '+p2);