My current regular expression only matches the nested pattern not the outermost @if....endif@ pattern. How can I modify my expression to match the outermost pattern. If the outermost pattern is removed from the string the expression should then match all before nested patterns. Many or the or-patterns are only relevant in the real world.
Regex:
(?<match>
@if\((?<statement>[^)]*)\){(?<ifblock>(?>
(?<open>@if\([^)]*\){)
|<script[^>]+>.*?</script>
|(?<valuetag>\@{(?<tag>[^}]+)})(?:(?:(\.|\$))(?<action>[^)@]+[)]))?
|(?<configtag>@(?:(?<tagtype>cc|dc|sc|wc)){(?<tag>[^}\.]*)(?:(?:\.)(?<action>(?:ToLower|ToUpper|MaxLength)))?}(?:cc|dc|sc|wc)@)
|(?<match>@weeknumber{(?<date>((?<valuetag>\@{(?<tag>[^}]+)})(?:(?:(\.|\$))(?<action>[^)@]+[)]))?|((0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-](19|20)\d\d)))}weeknumber@)
|(?<tag>\@{(?<tagname>[^}]+)}[.]ReplaceText\((?<replace>[^;]+)[;]{1}(?<with>[^)]+)\))
|(?<match>@(block|if)\((?<statement>[^)]*)\){(?<ifblock>.*)(?=)}end(block|if)@)
|[^}@]+
|@{value(\.[A-Z][0-9])?}
|(?<-open>}endif@)
)*)
(?(open)(?!))
(
}else{(?<elseblock>(?>
(?<open>@if\([^)]*\){)
|<script[^>]+>.*?</script>
|(?<valuetag>\@{(?<tag>[^}]+)})(?:(?:(\.|\$))(?<action>[^)@]+[)]))?
|(?<configtag>@(?:(?<tagtype>cc|dc|sc|wc)){(?<tag>[^}\.]*)(?:(?:\.)(?<action>(?:ToLower|ToUpper|MaxLength)))?}(?:cc|dc|sc|wc)@)
|(?<match>@weeknumber{(?<date>((?<valuetag>\@{(?<tag>[^}]+)})(?:(?:(\.|\$))(?<action>[^)@]+[)]))?|((0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-](19|20)\d\d)))}weeknumber@)
|(?<tag>\@{(?<tagname>[^}]+)}[.]ReplaceText\((?<replace>[^;]+)[;]{1}(?<with>[^)]+)\))
|(?<match>@(block|if)\((?<statement>[^)]*)\){(?<ifblock>.*)(?=)}end(block|if)@)
|[^}@]+
|@{value(\.[A-Z][0-9])?}
|(?<-open>}endif@)
)*)
(?(open)(?!))
)?
}endif@)
String:
@if(base.SiteBID=='SOS'){
<div class="floatleft reviewcontainer_outer" onclick="@if(base.IsSmartPhone=='False'){toogleReviewModalLightbox('@{house.id}', 0, 10);}endif@">
@if(house.latestreview.amount<greaterthen>2){<div class="sos_sprite reviews@{house.category} sos_inline onlinecat_review_gfx@{house.latestreview.totalrankcss} floatleft reviewcontainer_sprite" title="@{house.latestreview.totalrank}"></div><p class="broedtekst floatleft link">@{house.latestreview.amount} @cc{txt_guestbook_result}cc@</p>}endif@
</div>
@if(base.IsSmartPhone=='False'){toogleReviewModalLightbox('@{house.id}', 0, 10);}else{jhfr}endif@
}endif@
I want the expression to match the whole string from @if to endif@