Hello I have the following code in JS that detects me in a block of content if it has any of the following sequences of characters and they have to be replaced by images, the problem is that the replace function does not allow me to replace them. Here is the code:
function validarContenido(contenido){
var emoji = [":)","XD",":P",":(",":*","X_X","|**|"];
var icono = ["img/emojis/emoji1.png",
"img/emojis/emoji2.png",
"img/emojis/emoji3.png",
"img/emojis/emoji4.png",
"img/emojis/emoji5.png",
"img/emojis/emoji6.png",
"img/emojis/emoji7.png"];
for(var i=0; i<emoji.length; i++){
var estaEmoji = contenido.search(emoji[i]);
console.log(estaEmoji);
if(estaEmoji!=-1){
contenido = contenido.replace(emoji[i],icono[i]);
}
}
console.log(contenido);
return contenido;
}
And the error that throws me is the following:
Uncaught SyntaxError: Invalid regular expression: /:)/: Unmatched ')'
at String.search (<anonymous>)
at validarContenido (controlador.js:195)
at HTMLButtonElement.<anonymous> (controlador.js:151)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)