ES6 - RegExp match() 方法

此方法检索匹配项。

语法

str.match(regexp)

参数详细信息

  • Regexp − 正则表达式对象。

返回值

返回匹配项数组,如果未找到匹配项,则返回 null。

示例

var str = 'Welcome to ES6.We are learning ES6'; 
var re = new RegExp("We"); 
var found = str.match(re); 
console.log(found);  

输出

We