【发布时间】:2017-11-23 03:13:41
【问题描述】:
Regex r = new System.Text.RegularExpressions.Regex("(\\d+)(\\w)");
Match m = r.Match(" 123x ");
MessageBox.Show(m.Captures.Count.ToString());
MessageBox.Show(m.Captures[0].Value);
MessageBox.Show(m.Captures[1].Value);
这在运行时给了我异常
【问题讨论】:
-
我不太了解 .NET,但我认为您应该使用
.Groups,而不是.Captures。见stackoverflow.com/questions/3320823/… -
这是因为
m.Captures[1].Value是NULL。因此你得到System.ArgumentOutOfRangeException错误。您的预期结果是什么? -
因为
m.Captures的计数为1,因此m.Catures[1]给出System.ArgumentOutOfRangeException