为什么命名组位于组数组的末尾?
例如模式(具有命名和未命名组):
(?<digit>\d+)\|(?<main>\d+)\|(\d+)\|(?<abc>\d+)\|(\d+)
和文本:
123|456|789|10|11
为什么“789”和“11”位于数组的开头?
查看演示 systemtextregularexpressions.com
对不起我的英语:)
最佳答案
嗯...这只是 .NET Framework 中的一个实现选择。
documentation解释算法:
Both unnamed and named capturing groups can be accessed by number. Unnamed groups are numbered from left to right starting with 1. (The capturing group in index 0 (zero) represents the match as a whole.) Named groups are then numbered from left to right starting with a number that is one greater than the number of unnamed capturing groups.
这不一定适用于其他风格,例如 PCRE 按照它们在模式中出现的顺序分配组号,无论它们是否被命名。
关于c# - 正则表达式 - 为什么命名组位于组数组的末尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29399436/