Make the .*
not greedy (.*?
) so that it won't cover the following template names :
var matches = test.match(/\{\s*>\s*("[^"]*").*?\}/g)
This gives you the matches, not the submatches. To get the groups, use exec
:
var r = /\{\s*>\s*("[^"]*").*?\}/g, m;
while (m = r.exec(test)) {
console.log(m[1]);
}
Side notice : there was no need to escape the >
.