I need to replace text like ;)
or :p
by emoticon but I can\'t create a regex in order to detect this. Now i can detect only like :wink:
This function takes a string and returns a string with all the replacements found inside of the emots
object.
function replaceText(text) {
var emots = {
";)": "wink",
":)": "xxx",
":p": "xxx",
};
for(var key in emots){
if(emots.hasOwnProperty(key)){
text = text.replace(new RegExp(escapeRegExp(key), 'g'), '');
}
}
return text;
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}