I wanna replace several words in a text using replace() in javascript, how can I do that?
For example, if I wanna replace, \'Dave Chambers,
Use a regular expression with the alternator (|) and case insensitive modifier (/i):
var str = sometext.innerHTML,
reg = /Dave Chambers|David Chambers|Will Smith/i;
str = str.replace(reg, "Jackie Chan");
A shorter, more complex regex could be:
/Dav(?:e|id) Chambers|Will Smith/i;
And if there may be more than 1 occurrence, add the global modifier (g) to replace all:
/Dav(?:e|id) Chambers|Will Smith/ig;
You can learn more about regular expressions here, or by searching Google. You can see a working demo here.