其他分享
首页 > 其他分享> > es6初学——正则表达式

es6初学——正则表达式

作者:互联网

string: match()replace()search()split()

正则表达式常用的四个方法:

https://mp.weixin.qq.com/s?src=11&timestamp=1568280886&ver=1848&signature=mnQtCSf*fqpgtGTmi0RmPbLggDEoVvtkqY0lDGAW0XEgZEAJyNipWBiXcN6j*HYBCPA9jE5YCQQ8F0pGbOuP1Na9i6dxsAVCUUknBFVZFlM1OHwJ7bb*Z14P8nWtFML9&new=1

还有 compile

exec:

const RE_DATE = /(\d{4})-(\d{2})-(\d{2})/;

const matchObj = RE_DATE.exec('1999-12-31');
const year = matchObj[1]; // 1999
const month = matchObj[2]; // 12
const day = matchObj[3]; // 31


console.log(matchObj)

[ '1999-12-31',
  '1999',
  '12',
  '31',
  index: 0,
  input: '1999-12-31',
  groups: undefined ]

 

标签:es6,12,const,正则表达式,matchObj,1999,初学,prototype,31
来源: https://blog.csdn.net/from_shanghai/article/details/100778299