问题出.
在您的模式中。在正则表达式语言中,.
字符匹配任何字符(单行模式除外),因此您必须使用\
字符对其进行转义以仅匹配句点。
试试这个:
private static Regex MRDNumbers = new Regex(@"((\d+\.?){2,})+");
要捕获列表中所有匹配的数字,您可以尝试以下操作:
private Regex MRDNumbers = new Regex(@"(\d+?)(?:\.(\d+))+");
string input = "Above includes - Add/Remove Member To/From Nested Group - 1.24.12 / 1.24.13";
MRDNumbers.Matches(input).Cast<Match>().Dump();
var list =
(from m in MRDNumbers.Matches(input).Cast<Match>()
select
from g in m.Groups.Cast<Group>().Skip(1)
from c in g.Captures.Cast<Capture>()
select c.Value)
.ToList();
// [ [ 1, 24, 12 ], [ 1, 24, 12 ] ]
或流利的语法:
var list =
MRDNumbers.Matches(input).Cast<Match>()
.Select(m => m.Groups.Cast<Group>()
.Skip(1)
.SelectMany(g => g.Captures.Cast<Capture>())
.Select(c => c.Value))
.ToList();