본문 바로가기

Programming

javascript trim() 함수


String.prototype.ltrim = function() { var re = /\s*((\S+\s*)*)/; return this.replace(re, "$1"); } String.prototype.rtrim = function() { var re = /((\s*\S+)*)\s*/; return this.replace(re, "$1"); } String.prototype.trim = function() { return this.ltrim().rtrim(); }