Javascript String gsub(search, replacement)

Description

Javascript String gsub(search, replacement)


String.prototype.gsub = function(search, replacement){
 var regularExpression = {
  String: function(){
   return new RegExp(search, "g"); 
  },/*from   www  .j  a  va 2 s  . c  o  m*/
  RegExp: function(index, element){
   return new RegExp(search.source, "g"); ; 
  }
 };
 var searchRegular = regularExpression[search.constructor.name]();
 return this.replace(searchRegular, replacement);
};



PreviousNext

Related