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.