gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:21:47 25 4
gpt4 key购买 nike

我有正则表达式,"((?:\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.]+");

.NET Fiddle

关于c# - 匹配不同捕获组中的数字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23888882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com