1var str = "JavaScript replace method test";
2var res = str.replace("test", "success");
3//res = Javscript replace method success
1const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
2
3console.log(p.replaceAll('dog', 'monkey'));
4// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
1const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
2
3console.log(p.replaceAll('dog', 'monkey'));
4// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
5
6// global flag required when calling replaceAll with regex
7const regex = /Dog/ig;
8console.log(p.replaceAll(regex, 'ferret'));
9// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
10
1
2// change echo with some else
3// unique
4let gelen.icerik="abc echo abc echo";
5let bulunanlar = [...gelen.icerik.matchAll(/echo.*;/g)];
6let bulunanlarDizisi = [];
7for (const bulunan of bulunanlar) {
8 bulunanlarDizisi.push(bulunan[0]);
9 console.log(bulunan[0]);
10}
11bulunanlarDizisi = [...new Set(bulunanlarDizisi)]; // tekillestirildi
12bulunanlarDizisi = bulunanlarDizisi.sort((x, y) => y.length - x.length); // uzundan kisaya
13bulunanlarDizisi.forEach((bulunan) => {
14 let bununla = bulunan + ` echo "\\n";`;
15 gelen.icerik = gelen.icerik.split(bulunan).join(bununla);
16});