匹配不同捕获组中的数字字符串

本文关键字:数字 数字字符 字符串 | 更新日期: 2023-09-27 18:05:25

我有一个正则表达式,"((?:'d*'.)?'d+)",我想获得不同捕获组中的所有数字。

像这样:

String sInput  = "20004 8 19 0 1 25. 1. 0. 0. 8 8 6366. 305.4 305.4 15915 8 4 25. 0."
String sRegExDef="((?:'d*'.)?'d+)";
MatchCollection matches = Regex.Matches(sInput, sRegExDef, RegexOptions.IgnoreCase);
matches[0].Value="20004";
matches[1].Value="8";
matches[2].Value="19";
.
.
.
matches[n].Value="...";

我要找的是一种方法来获得不同的捕获组的数字。

匹配不同捕获组中的数字字符串

你可以这样做:

string[] matches = Regex.Split(sInput, @"[^'d.]+");

。净小提琴

  • 使用Casimir et Hippolyte溶液更新。

如果你想要每个数字(点后面的数字作为新数字)

 String sRegExDef=@"((?:'d*)?'d+)";