I suggest you look up how to do regular expressions, they help outheaps. For just a basic string (using just letters or numbers assymbols can have a different meaning) then you can use my code as anexample and put the likes of the following
code:
var replace1 = /text/gi;
function ...(...){
string = string.replace(replace1,"text to replace it with");
}
For symbols like / \ . * $ ^ + ? etc then you will need to prefix those characters with \
There are a heap more thing involved in regular expressions but those few things will get you started (though I suggest you try learning more).