Reputation: 3924
My sample string is
var str = "My name is {name}.from {area}";
I need both {name} and {area} separately from that string.
I TRIED
var s = "My name is {name}.from {area}";
var matches = s.match(/\{(.*?)\}/);
console.log(matches);
It gives only the first occurence. How to get both the strings {name} {area}.
Upvotes: 2
Views: 2157
Reputation: 5768
Add the global flag to the regular expression:
var matches = s.match(/\{(.*?)\}/g);
This will get you all of the matches of the regular expression, not just the first one.
Upvotes: 6