.NET Regex balancing groups expression - matching when not balanced

后端 未结 2 1118
灰色年华
灰色年华 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

    Have you checked what it is matching in the second case? Since you don't have any anchors, I think the engine starts the match just after the first '{'. From there, until the end, the string matches.

    Try surrounding the pattern with \A and \z.

提交回复
热议问题