Javascript regular expression for string trim funtion

<script language="javascript"> String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } </script>

Usage :
alert(" test ".trim());