I'm trying to use regexp in javascript to match a group of patterns but for some reason when I'm trying to console.log the group, it's just logging out characters instead of the entire pattern. What I am doing wrong? Also, the g flag is required for this pattern.
var string = "group1group2group3 group4group4group4 group1group2group3";
var matches = string.match(new RegExp("(group1)(group2)(group3)", "g"));
console.log(matches[0][0]+matches[0][1]+matches[0][2]);
Result:
gro
Expected Result:
group1group2group3