Nodejs String Replace replaceAll(find, replace)

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

Method Source Code

// replaceAll/*from  w  w w. j a  v  a2s  . c o m*/
String.prototype.replaceAll = function(find, replace) {
   var str = this;
   return str.replace(new RegExp(find, 'g'), replace);
};

Related

  1. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
        var str = this;
        return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
    };
    
  2. replaceAll(find, replace)
    function escapeRegExp(string) {
        return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    String.prototype.replaceAll = function (find, replace) {
        return this.replace(new RegExp(escapeRegExp(find), 'g'), replace);
    
  3. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
      return this.replace(new RegExp(find, 'g'), replace);
    };
    
  4. replaceAll(find, replace)
    String.prototype.replaceAll = function(find, replace){
      find = find.escapeRegExp();
      return this.replaceAllRegExp(find, replace);
    };
    
  5. 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;
    };
    
  6. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
        var str = this;
        return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
    };
    
  7. 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);
    };
    
  8. replaceAll(from, to)
    String.prototype.replaceAll = function(from, to)  {
       var str = this;
       while(str.indexOf(from)>=0) {
          str = str.replace(from, to);
       return str;
    
  9. 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);
    };
    ...