I need a function that will Find smileys in text and replaces them with a replacer.
function myFunc(text, replacer) {
return text.replace(/:(|:)|<3|:'(/g, replacer);
}
myFunc("Hi, :) I'm Sad :( :'( I can't but love <3 you", "*"));
//Output I want: Hi, * I'm Sad * * I can't but love * you
CodePudding user response:
(
and )
have to be escaped in regular expressions with \
function myFunc(text, replacer) {
return text.replace(/:\(|:\)|<3|:'\(/g, replacer);
}
const result = myFunc("Hi, :) I'm Sad :( :'( I can't but love <3 you", "*");
console.log(result)