I've got a string which i want split up in specific segments but i cant match the correct segment of the string because of two occurences of the same pattern.
My string:
@if(text.text isempty){<customer_comment>@cc{txt_without_comments}cc@</customer_comment>}else{@if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}endif@}endif@
I need to match: @if(text.text isempty){@cc{txt_without_comments}cc@}else{....}endif@
and not the nested dots in the else-block.
Here is my incomplete regex:
(?<match>(?<open>@if\((?<statement>[^)]*)\)\s*{)(?<ifblock>(.+?)(?:}else{)(?<elseblock>.*))(?<-open>)}endif@)
This regex is too greedy in the ifblock group it supposed to stop at the first }else{ pattern.
Edit: This is the exact result i want to produce:
match: @if(text.text isempty){<customer_comment>@cc{txt_without_comments}cc@</customer_comment>}else{@if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}endif@}endif@
statement: text.text isempty
ifblock: <customer_comment>@cc{txt_without_comments}cc@</customer_comment>
elseblock: @if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}endif@