I'm working with Jquery, and I wrote this code for replace all string variable. But not working.
var s = ":) :) :)".replace(new RegExp(':)','g'),'<img src="../images/smiley.gif" />');
alert(s);
How can i solve this problem? Thanks
You must escape the parenthesis :
new RegExp(':\\)','g')
As you can see, there are two \ : one because the ) must be escaped in a regex, and one because a \ must be escaped in a string literal.
It's simpler to use a regular expression literal :
var s = ":) :) :)".replace(/:\)/g,'<img src="../images/smiley.gif" />');