Is this a bug in .NET's Regex.Split?

前端 未结 2 880
醉酒成梦
醉酒成梦 2020-12-11 20:48

I have two regular expressions, for use with Regex.Split:

(?<=\\G[^,],[^,],)

and

(?<=\\G([^,],){2})


        
相关标签:
2条回答
  • 2020-12-11 21:28

    From docs:

    If capturing parentheses are used in a Regex.Split expression, any captured text is included in the resulting string array.

    You have a capture group in your second expression. Try non-capturing parens:

    (?<=\G(?:[^,],){2})
    
    0 讨论(0)
  • 2020-12-11 21:47

    From the documentation for Regex.Split

    If capturing parentheses are used in a Regex.Split expression, any captured text is included in the resulting string array.

    The internal parentheses are capturing. Try using (?:[^,],) instead.

    0 讨论(0)
提交回复
热议问题