Javascript Regular Expressions match each word

Description

Javascript Regular Expressions match each word


let searchString = "time time's time time";
let pattern = /t\w*e/g;
let matchArray;/*from  ww w  .j av a  2s  . c  o  m*/

let str = "";
while((matchArray = pattern.exec(searchString)) != null) {
    str+="at " + matchArray.index + " we found " + matchArray[0];
}

console.log(str);



PreviousNext

Related