Nodejs String Replace replaceAll(search, replace)

Here you can find the source of replaceAll(search, replace)

Method Source Code

// Prototype:/* w  ww. j  ava 2 s . c om*/

String.prototype.replaceAll = function(search, replace) {
   // If replace is null, return original string; otherwise, it will replace search string with 'undefined'.

   if(!replace) {
      return this;
   }

   return this.replace(new RegExp(helpers.escapeRegExp(search), 'g'), replace);
};

Related

  1. replaceAll(search, replace)
    String.prototype.replaceAll = function(search, replace) {
        if (replace === undefined) {
            return this.toString();
        return this.split(search).join(replace);
    
  2. replaceAll(search, replace)
    String.prototype.replaceAll = function (search, replace) {
      return this.replace(new RegExp(search, 'g'), replace);
    };
    String.prototype.ltrim = function () {
      return this.replace(/^\s+/,"");
    };
    String.prototype.rtrim = function () {
      return this.replace(/\s+$/,"");
    };
    ...
    
  3. replaceAll(search, replace)
    String.prototype.replaceAll = function (search, replace) {
        if (replace === undefined) {
            return this.toString();
        return this.replace(new RegExp('[' + search + ']', 'g'), replace);
    };
    
  4. replaceAll(search, replace)
    String.prototype.replaceAll = function (search, replace) {
        'use strict';
        return this.split(search).join(replace);
    };
    
  5. replaceAll(search, replace)
    String.prototype.replaceAll = function(search, replace){
      return this.split(search).join(replace);
    
  6. replaceAll(search, replacement)
    String.prototype.replaceAll = function(search, replacement) {
        var target = this;
        return target.split(search).join(replacement);
    };
    
  7. replaceAll(search, replacement)
    String.prototype.replaceAll = function(search, replacement) {
        var target = this;
        return target.replace(new RegExp(search, 'g'), replacement);
    };
    
  8. replaceAll(search, replacement)
    String.prototype.replaceAll = function(search, replacement) {
      'use strict';
      return this.split(search).join(replacement);
    };
    
  9. replaceAll(search, replacement)
    String.prototype.replaceAll = function(search, replacement) {
        let target = this;
        return target.replace(new RegExp(search, 'g'), replacement);
    };