【getmonth】...{//author:meizzvaro={M :this.getMonth() 1//...

发布时间:2021-04-04 07:50:43

正则表达式y+Date.prototype.Format = function(fmt) { //author:meizz var o = { M+ :this.getMonth()+1,//月份 d+ :this.getDate(),//日 h+ :this.getHours(),//小时 m+ :this.getMinutes(),//分 s+ :this.getSeconds(),//秒 q+ :Math.floor((this.getMonth()+3)/3),//季度 S :this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1,(this.getFullYear()+).substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp((+ k +)).test(fmt)) fmt = fmt.replace(RegExp.$1,(RegExp.$1.length==1) (o[k]) :((00+ o[k]).substr((+ o[k]).length))); return fmt; } 在网上看到的这段JS代码.想问下大家这句 if(/(y+)/.test(fmt))/(y+)/是什么意思呢 ,

网友回答

【答案】 正则表达式中y只是一个普通文本,用于匹配字母y
  y+的意思是:匹配1个到多个y
  (y+)的意思是:y+匹配到的内容可能通过分组来取到,这里是通过第一个分组取到.从后面的代码中可以看出,RegExp.$1就是取到的y+匹配到的内容
以上问题属网友观点,不代表本站立场,仅供参考!