I need two regular expressions to identify if .. then .. else .. endif
section and their parts.
From an expression which could be like below:
Example 1:
5 + 10 * (if (4 + 4.5) > 0 then 20 else 45 endif) + 2
Example 2:
if (20 == 10) then 10 endif
Example 3:
if (20/10 != 2) then (2 * 10) else (3 * 4) endif
Expected Result:
A regular expression which could give me the
if..endif
part in an expression For ex. from Example 1 I should receiveif (4 + 4.5) > 0 then 20 else 45 endif
separatelyA regular expression which could give me the
if..endif
parts. For ex. from Example 1 I should receive:
Left-Comparator: (4 + 4.5)
Operator: >
Right-Comparator: 0
ThenPart: 20
ElsePart: 45
(could be null or string.Empty)
Points to Note:
else
is optional.if..endif
could be the only expression or it could be part of a expression.then
&else
can have an expression or a static value.- The conditional operators that could be used in if condition are
>, <, ==, !=, >=, <=
- Regular Expression should work in C# application.