I know what is happening, but I do not know how to solve it because I am a novice in regular expressions.
The regular expression, takes all the expression, because it takes the initial brackets of {{username
and the end of day}}
, then it wraps all the code between them.
How should the regular expression be?
var str = "Welcome back {{username}}, how are you ? today is {{day}}",
regex = /{{.+}}/g,
matches = str.match(regex);
console.log(matches); // I was waiting for : [{{username}}, {{day}}]