es6初学——正则表达式
作者:互联网
string: match()
、replace()
、search()
和split()
String.prototype.match
调用RegExp.prototype[Symbol.match]
String.prototype.replace
调用RegExp.prototype[Symbol.replace]
String.prototype.search
调用RegExp.prototype[Symbol.search]
String.prototype.split
调用RegExp.prototype[Symbol.split]
正则表达式常用的四个方法:
还有 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