.NET Regex balancing groups expression - matching when not balanced

后端 未结 2 1160
灰色年华
灰色年华 2021-01-26 23:55

.NET balanced group regexes make my head explode. I\'ve got this string i\'m trying to match:

other stuff blah blah....
                    {
                           


        
2条回答
  •  长发绾君心
    2021-01-27 00:39

    Not to be a kill joy but what you're attempting to do with a regular expression is boggling your mind because it's simply not possible. Regular expressions are a class of finite automata and do not posses enough state in which to peform recursive/nested matching. You'll need a context free grammar of sorts in order to get this working.

    There are some regular expression engines which do support a notion of recursion. These are not strictly speaking regular expressions though. Can you tell us what engine you are using because it's possible it has a recursion function which will help out this scenario.

提交回复
热议问题