1// Valor retornado: “Aprendendo JavaScript. JavaScript é na DevMedia”
2exemplo = "Aprendendo Javascript. JAVAScript é na DevMedia ";
3resultado = exemplo.replace(/javascript/gi, "JavaScript");
1var string = "Javascript is fun";
2var newString = string.replace("fun", "Awesome");
3console.log(newString); // Javascript is Awesome
1const p = 'dog dog cat rat';
2const regex = /dog/gi;
3
4console.log(p.replace(regex, 'cow'));
5//if pattern is regular expression all matches will be replaced
6//output: "cow cow cat rat"
7
8console.log(p.replace('dog', 'cow'));
9// If pattern is a string, only the first occurrence will be replaced.
10//output: "cow dog cat rat"
1var text = "Sentence with old text"
2alert( text.replace("old text", "new text") ); // Sentence with new text
1var frase = "Son tres mil trescientos treinta y tres con nueve";
2frase = frase.replace("tres","dos");
3console.log(frase);
4//Son dos mil trescientos treinta y tres con nueve