script
javascript trim
준용
2008. 8. 27. 22:17
function trim(str) {javascript에는 공백제거를 하는 trim함수가 없다 ;;
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
그래서 정규표현식을 사용하여 공백을 제거한다.
정규표현식
^ - 처음시작(beginning of line)
\s - 공백(whitespace character)
$ - 끝라인(end of line)