I have a text like this:
UseProp1?(Prop1?Prop1:Test):(UseProp2?Prop2:(Test Text: '{TextProperty}' Test Reference:{Reference}))
I'm trying to use regex in c# to extract the nested if/else-segments.
To find '?' I've used:
Pattern 1: \?\s*(?![^()]*\))
and to find ':' I've used:
Pattern 2: \:\s*(?![^()]*\))
This works fine when there is one level of parentheses but not when nesting them.
I've used this online tool to simplify the testing: http://regexstorm.net/tester (and insert pattern-1 and input from above)
As you can see, it highlights two matches but I only want the first. You'll also notice that first parentheses is overlooked but not the next one with the nested levels
I expect the match list to be:
1) UseProp1
2) (Prop1?Prop1:Test):(UseProp2?Prop2:(Test Text: '{TextProperty}' Test Reference:{Reference}))
What I'm getting now is:
1) UseProp1
2) (Prop1?Prop1:Test):(UseProp2
3) Prop2:(Test Text: '{TextProperty}' Test Reference:{Reference}))
\w+)|\((?(?>[^()]+|(?\()|(?<-o>\)))*(?(o)(?!)))\)):(?:(?\w+)|\((?(?>[^()]+|(?\()|(?<-o>\)))*(?(o)(?!))))\))`. See named groups values.