I want to extract all words enclosed in curly braces, so I have an expressions like this
foo {bar} moo {mar}
The string to match may have any number of these words, but I'm starting to think I'm approaching this problem in the wrong way.
My attempt
And I've tried to extract the words braces into groups so I can use every single match. So, I made a regex:
String rx = ".*\\{({GROUP}\\w+)\\}.*";
Note: I'm using JRegex syntax so I need to escape some of the curlies.
Result
The result I get is a single (albeit correct) match bar
, whilst I expect two matches bar
andmar
. What have I misunderstood, and how do I correct it? I probably need to use some other quantifier for the .
part, but I hope you can help me with that too.
Many thanks in advance!