Return a new string with the value stripped from the left of the string - Node.js String

Node.js examples for String:Strip

Description

Return a new string with the value stripped from the left of the string

Demo Code

/**/*from   www  . j  a  v  a 2 s.  c  om*/
 * Return a new string with the value stripped from the left of the string
 * @version 1.1.1
 * @date July 22, 2010
 * @package jquery-sparkle {@link http://www.balupton/projects/jquery-sparkle}
 * @author Benjamin "balupton" Lupton {@link http://www.balupton.com}
 * @copyright (c) 2009-2010 Benjamin Arthur Lupton {@link http://www.balupton.com}
 * @license GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 */
String.prototype.stripLeft = String.prototype.stripLeft || function(value,regex){
  // Strip a value from the left, with optional regex support (defaults to false)
  value = String(value);
  var str = this;
  if ( value.length ) {
    if ( !(regex||false) ) {
      // We must escape value as we do not want regex support
      value = value.replace(/([\[\]\(\)\^\$\.\?\|\/\\])/g, '\\$1');
    }
    str = str.replace(eval('/^'+value+'+/g'), '');
  }
  return String(str);
}

Related Tutorials