I had a regex to find single if-then-else condition.
string pattern2 = @"if( *.*? *)then( *.*? *)(?:else( *.*? *))?endif";
Now, I need to extend this & provide looping if conditions. But the regex is not suitable to extract the then & else parts properly.
Example Looped IF condition:
if (2 > 1) then ( if(3>2) then ( if(4>3) then 4 else 3 endif ) else 2 endif) else 1 endif
Expected Result with Regex:
condition = (2>1) then part = ( if(3>2) then ( if(4>3) then 4 else 3 endif ) else 2 endif) else part = 1
I can check if else & then part have real values or a condition. Then i can use the same regex on this inner condition until everything is resolved.
The current regex returns result like:
condition = (2 > 1) then part = ( if( 3>2) then ( if(4>3) then 3 else part = 3
Meaning, it returns the value after first "else" found. But actually, it has to extract from the last else.
Can someone help me with this?