Javascript String normalize(s)

Description

Javascript String normalize(s)


/**/*from  w  ww  . j a  va 2 s .c o  m*/
 * Normalizes a string by replacing multiple-instances
 * of parameter `s` with the singular-instance.
 * ex. "///path//to/my//endpoint//".normalize('/') => "/path/to/my/endpoint/"
 */
String.prototype.normalize = function(s) {
    return this.replace(new RegExp(s + "+", "gm"), s);
};



PreviousNext

Related