<script> Date.prototype.format=function(){ var d=this; //严格匹配 yyyy-mm-dd hh-mm-ss var reg1=/yyyy-mm-dd hh-m-s/; //匹配 yyyy*mm*dd hh*mm*ss *为任意一个除\r\n之外的字符 中间为任意多个空格 var reg2=/y{4}.m{2}.dd\s+hh.mm.ss/; reg1.test(arguments[0]); reg2.test(arguments[0]); return d.getFullYear()+'-' + d.getMonth()+'-' + d.getDate()+' ' + d.getHours()+'-' + d.getMinutes()+'-' + d.getSeconds(); }; var date=new Date(); console.log(date.format('yyyy—mm-dd hh-mm-ss')); console.log(date); var str='oooo'; var reg3=/o+/,reg4=/o+?/; console.log(reg3.exec(str)); console.log(reg4.exec(str)); console.log(str.match(reg4)); </script>