Javascript String squeeze()

Description

Javascript String squeeze()


String.prototype.squeeze = function() {
    var set = arguments.length > 0 ? "["+Array.prototype.join.apply(arguments, ["]|["])+"]" : ".|\\n",
        regex = new RegExp("("+set+")\\1+", "g");
    //from  w  ww  .ja  v  a 2  s.  c om
    return this.replace(regex, "$1");
}



PreviousNext

Related