J'ai une chaîne que je veux séparer en segments spécifiques mais je ne peux pas correspondre au segment correct de la chaîne à cause de deux occurrences du même modèle.Trouver des segments spécifiques en utilisant regex
Ma chaîne:
@if(text.text isempty){<customer_comment>@cc{txt_without_comments}[email protected]</customer_comment>}else{@if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}[email protected]}[email protected]
je dois correspondre: @if (text.text isempty) {@ cc {} txt_without_comments cc @} else {....} endif @
et pas les points imbriqués dans l'autre bloc.
Voici mon regex incomplète:
(?<match>(?<open>@if\((?<statement>[^)]*)\)\s*{)(?<ifblock>(.+?)(?:}else{)(?<elseblock>.*))(?<-open>)}[email protected])
Cette regex est trop gourmand dans le groupe ifblock il censé arrêter au premier} else {motif.
Edit: Ceci est le résultat exact que je veux produire:
match: @if(text.text isempty){<customer_comment>@cc{txt_without_comments}[email protected]</customer_comment>}else{@if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}[email protected]}[email protected]
statement: text.text isempty
ifblock: <customer_comment>@cc{txt_without_comments}[email protected]</customer_comment>
elseblock: @if(text.answer=='no'){<customer_comment>@{text.text}</customer_comment>}else{<answer>@{text.text}</answer>}[email protected]
Veuillez fournir le résultat exact. –
Mon résultat recherché est publié à la question. –