Nodejs String Replace replaceAll(from, to)

Here you can find the source of replaceAll(from, to)

Method Source Code

// JavaScript Document
String.prototype.replaceAll = function(from, to)  {
   var str = this;
   while(str.indexOf(from)>=0) {
      str = str.replace(from, to);/*  w  w w. ja v a 2  s .  c  o  m*/
   }
   return str;
}

Related

  1. replaceAll(find, replace)
    String.prototype.replaceAll = function(find, replace){
      find = find.escapeRegExp();
      return this.replaceAllRegExp(find, replace);
    };
    
  2. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
      return this.replace(new RegExp(find, 'g'), replace);
    };
    String.prototype.sanitize = function () {
      var s = this.replace(/\W+/g, "");
      return s;
    };
    
  3. replaceAll(find, replace)
    String.prototype.replaceAll = function(find, replace) {
      var str = this;
      return str.replace(new RegExp(find, 'g'), replace);
    };
    
  4. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
        var str = this;
        return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
    };
    
  5. replaceAll(from, to)
    String.prototype.replaceAll = function (from, to) {
      if (from == ".")
        return this.replace(/\./g, to);
      var rgx = new RegExp(from, 'g');
      return this.replace(rgx, to);
    };
    
  6. replaceAll(from, to, caseSensitive)
    String.prototype.replaceAll = function(from, to, caseSensitive){
        var target;
        if (caseSensitive === true) {
            target = new RegExp(from, 'g');
        }else{
            target = new RegExp(from, 'gi');
        return this.replace(target, to);
    };
    ...
    
  7. replaceAll(oldStr, newStr)
    String.prototype.replaceAll = function(oldStr, newStr){
      let s = this.toString();
      if(oldStr instanceof RegExp){ let a = this.match(oldStr); oldStr = a === null ? '' : a[0]; }
      if(oldStr !== '') while(s.indexOf(oldStr) != -1){ s = s.replace(oldStr, newStr) }
      return s;
    };
    
  8. replaceAll(oldString, replacement)
    String.prototype.replaceAll = function (oldString, replacement) {
        var a = this;
        while (a.indexOf(oldString) != -1) {
            a = a.replace(oldString, replacement);
        return a;
    
  9. replaceAll(oldValue, newValue)
    String.prototype.replaceAll = function (oldValue, newValue) {
      return this.replace(new RegExp(oldValue, 'g'), newValue);
    };