RegExp练习

https://www.liaoxuefeng.com/wiki/1022910821149312/1023021582119488

'use strict';


var re = /^\<([\s\w]+)\>\s(\w+\@\w+\.(com|org))$/;

// var re = /^\<([\s\w]+)\>\s(\w+\@\w+\.org|com)$/;

console.log(re.test('<Tom Paris> tom@voyager.org'))
console.log(re.exec('<Tom Paris> tom@voyager.org'))


// 测试:
var r = re.exec('<Tom Paris> tom@voyager.org');
if (r === null || r.toString() !== ['<Tom Paris> tom@voyager.org', 'Tom Paris', 'tom@voyager.org'].toString()) {
    console.log('测试失败!');
}
else {
    console.log('测试成功!');
}

OUTPUT

true
[
  '<Tom Paris> tom@voyager.org',
  'Tom Paris',
  'tom@voyager.org',
  'org',
  index: 0,
  input: '<Tom Paris> tom@voyager.org',
  groups: undefined
]
测试失败!

上一篇:JS获取当前时间的前一个小时及格式化时间


下一篇:bypass