js 正则表达式有两种声明方式
- 构造函数
- 字面量
// 构造函数创建正则表达式对象
// 第一个参数是正则表达式, 第二个参数是匹配模式
let regex = new RegExp('abc', 'i')
// test 方法. 正则表达式是否匹配字符串
console.log(regex.test('abcdef'));
console.log(regex.test('Abcdef'));
// 字面量创建正则表达式对象
regex = /abc/i
console.log(regex.test('abcd'));