const s = "cat hat bat"; // a global regex collects every match into an array const words = s.match(/\wat/g); console.log(words);
global match returns all hits