Reputation: 1479
I'm trying to write a Regex
on Java for extracting the elements between double curly braces
Example :
I am very much new to java...{{envelope|func"{{aa}}{{ds}}|{{abc.xyz}}"}} and i want to know.... more.
I tried this regex but it doesn't return the first element full
{\{(.*?)(?:\{\{(.*?)\}\})*\}\}
I want to extract as the following :
Upvotes: 3
Views: 156
Reputation: 785058
Converting my comment to an answer. This is assuming between {{
and }}
we have all non-whitespace characters.
This regex is based on lookahead and alternation inside the lookahead. Captured groups are part of lookahead itself.
\{\{(?=((?:(?!\{\{|}})\S)*+|\S*)}})
Or in Java:
final String regex = "\\{\\{(?=((?:(?!\\{\\{|\\}})\\S)*+|\\S*)\\}})";
Upvotes: 2