这是.NET的正则表达式引擎一个错误? [英] Is this a bug in .NET's RegEx engine?
问题描述
我有两个定期EX pressions标准,使用 Regex.Split
:
I have two regular expressions, for use with Regex.Split
:
(?<=\G[^,],[^,],)
和
(?<=\G([^,],){2})
在分割字符串A,B,C,D,E,F,G,
,第一个结果是:
When splitting the string "A,B,C,D,E,F,G,"
, the first one results in:
A,B,
C,D,
E,F,
G,
和在第二结果
A,B,
A,
C,D,
C,
E,F,
E,
G,
这是怎么回事呢?我认为,(X){2}
总是等同于 XX
,但我不知道了。在我的实际问题,我需要做这样的事情更复杂了不少,而我需要做的是69倍,所以只是重复的模式不太理想。
What is going on here? I thought that (X){2}
was always equivalent to XX
, but I'm not sure anymore. In my actual problem, I need to do something like quite a bit more complex, and I need to do it sixty nine times, so just repeating the pattern is less than ideal.
推荐答案
从为的 Regex.Split
如果捕获括号在一个Regex.Split EX pression使用,任何捕获文本被包含在生成的字符串数组。
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.
这篇关于这是.NET的正则表达式引擎一个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!