Answers for "replaceAll alternative with string value javascript"

16

replaceAll alternative with string value javascript

function replaceAll(str, find, replace) {
    var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan");
Posted by: Guest on July-22-2019
0

replace all javascript

// change echo with some else
// unique
let gelen.icerik="abc echo abc echo";
let bulunanlar = [...gelen.icerik.matchAll(/echo.*;/g)];
let bulunanlarDizisi = [];
for (const bulunan of bulunanlar) {
  bulunanlarDizisi.push(bulunan[0]);
  console.log(bulunan[0]);
}
bulunanlarDizisi = [...new Set(bulunanlarDizisi)]; // tekillestirildi
bulunanlarDizisi = bulunanlarDizisi.sort((x, y) => y.length - x.length); // uzundan kisaya
bulunanlarDizisi.forEach((bulunan) => {
  let bununla = bulunan + ` echo "\\n";`;
  gelen.icerik = gelen.icerik.split(bulunan).join(bununla);
});
Posted by: Guest on August-05-2021

Code answers related to "replaceAll alternative with string value javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language