我有以下字符串:
"121 fd412 4151 3213, 421, 423 41241 fdsfsd"
我需要获取3213和421 - 因为它们前面都有空格,并且后面有逗号。
结果将被设置在字符串数组中...我该怎么做?
"\\d+"
可以捕获每个整数。
"\s\\d+(,)"
会引发一些内存错误。
编辑。
数字左侧 (<-)
有空格,右侧有逗号 (->)
编辑2。
string mainString = "Tests run: 5816, 8346, 28364 iansufbiausbfbabsbo3 4";
MatchCollection c = Regex.Matches(a, @"\d+(?=\,)");
var myList = new List<String>();
foreach(Match match in c)
{
myList.Add(match.Value);
}
Console.Write(myList[1]);
Console.ReadKey();