0

How to capture if-statement block. I've capture the else-statement block in a named Group. My current solution is at this permalink: http://regexhero.net/tester/?id=7663e386-fcc0-4f19-b613-e9e58374a5d7

@if\([^)]*\)\s*{(((?>(?<open>@if\([^)]*\)\s*{)|@{[^}]*}|[^}@]+|(?:}else{(?<else>([^}]*))(?=}endif@))|(?<-open>}endif@)))*(?(open)(?!)))}endif@

Content inside statement block are html related. I.e.

@if(prevbutton.visible=='True'){
    <div style="float:left; display:inline; margin-right: 5px; padding-top:7px;">
        <span class="arrows_prev" id="prevbottom" title="@{prevbutton.toindex}" rel="prev" data-page-number="@{prevbutton.toindex}"></span>
    </div>
}else{
    test
}endif@
Yannick Meeus
  • 5,643
  • 1
  • 35
  • 34

1 Answers1

0

Took another approach for solving the problem. Here is my solution:

(?<if_else>(?<=@if\([^)]*\){).*(?=}else{))|(?<if>(?<=@if\([^)]*\){).*(?=}endif@))|(?<else>(?<=}else{)[^}]*(?=}endif@))
Sam Axe
  • 33,313
  • 9
  • 55
  • 89