Remove specified characters from start and end of string. - Node.js String

Node.js examples for String:String Start

Description

Remove specified characters from start and end of string.

Demo Code

  String.prototype.strip = function(characters) {
    // summary://from  w ww  . j a v a 2s .co m
    //     Remove specified characters from start and end of string.
    // param: characters
    //     String of characters to remove.
    return this.replace(new RegExp('(^[' + characters + ']+)|([' + characters + ']+$)', 'g'), '');
  };

Related Tutorials