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     
广告

© . All rights reserved.