1
我有一個字符串,我想分割在特定的段,但我不能匹配正確的段的字符串,因爲兩個相同的模式發生。使用正則表達式查找特定的段
我的字符串:
@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]
我需要匹配:@if(text.text的isEmpty){@ CC {} txt_without_comments CC @}其他{....} ENDIF @
和而不是else塊中的嵌套點。
這裏是我的不完整的正則表達式:
(?<match>(?<open>@if\((?<statement>[^)]*)\)\s*{)(?<ifblock>(.+?)(?:}else{)(?<elseblock>.*))(?<-open>)}[email protected])
這正則表達式是ifblock組也應該停止在第一}其他{圖案太貪婪。
編輯: 這是確切的結果,我想製作:
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]
請提供確切的預期結果。 –
我想要的結果發佈到問題。 –