Use the regular expression literal, /[m]/ , instead of letting the string '[m]' get implicitly converted to the regular expression. This way you can add the /g flag ("replace all"):
$.html( aData[2].replace(/[m]/g,'[media]') )
although I have to add that you really want \[m\] , not [m] , so that you match literal square brackets:
$.html( aData[2].replace(/\[m\]/g,'[media]') )
ruakh source share