Nodejs String Replace replaceAll(source,target)

Here you can find the source of replaceAll(source,target)

Method Source Code

String.prototype.replaceAll = function(source,target){
   var val = this;
   while(val.indexOf(source)>-1){
      val = val.replace(source,target);/*w w w  .ja  va2 s.  c  o  m*/
   }
   return val;
};

Related

  1. replaceAll(search, replacement)
    'use strict';
    String.prototype.replaceAll = function(search, replacement) {
      var target = this;
      return target.split(search).join(replacement);
    };
    
  2. replaceAll(search, replacement)
    String.prototype.replaceAll = function (search, replacement) {
        var escapeRegExp = (str) => {
            return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
        var target = this;
        return target.replace(new RegExp(escapeRegExp(search), 'g'), replacement);
    };
    
  3. replaceAll(search, replacement)
    String.prototype.replaceAll = function (search, replacement) {
        var ret = this.toString().replace(search, replacement);
        while (ret.indexOf(search)!=-1) {
            ret = ret.replace(search, replacement);
        return ret;
    };
    String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/gm, '');
    ...
    
  4. replaceAll(search, replacement)
    String.prototype.replaceAll = function (search, replacement) {
      var target = this;
      var s1 = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
      return target.replace(new RegExp(s1, 'g'), replacement);
    };
    
  5. replaceAll(source, target)
    String.prototype.replaceAll = function (source, target) {
      return this.replace(new RegExp(source, "g"), target);
    };
    
  6. replaceAll(str, replaceStr)
    'use strict';
    String.prototype.replaceAll = function(str, replaceStr) {
        return this.replace(new RegExp(str, 'gm'), replaceStr);
    };
    
  7. replaceAll(str, replacement)
    String.prototype.replaceAll = function(str, replacement) {
      var regex;
      regex = new RegExp(str, "ig");
      return this.replace(regex, replacement);
    };
    
  8. replaceAll(str1, str2, ignore)
    String.prototype.replaceAll = function(str1, str2, ignore) 
      return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
    
  9. replaceAll(str1, str2, ignore)
    'use strict';
    String.prototype.replaceAll = function(str1, str2, ignore) 
        return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);