C# 如何从C中的捕获函数中捕获值#

C# 如何从C中的捕获函数中捕获值#,c#,regex,C#,Regex,当我想使用C#中的capture函数捕获值时,我遇到了一个问题。 我的代码在一个字符串中查找许多模式,因此我使用match collection,然后对每个匹配使用Capture函数。但是当我想替换captureOut.value时,它不起作用 我的代码: MatchCollection matches = Regex.Matches(string, @"\d*\.*\d+\s") foreach (Match matchOut in matches) { foreach (Captu

当我想使用C#中的
capture
函数捕获值时,我遇到了一个问题。 我的代码在一个字符串中查找许多模式,因此我使用match collection,然后对每个匹配使用
Capture
函数。但是当我想替换captureOut.value时,它不起作用

我的代码:

MatchCollection matches = Regex.Matches(string, @"\d*\.*\d+\s")

foreach (Match matchOut in matches)
{
    foreach (Capture captureOut in matchOut.Captures)
    Match match1 = Regex.Match(captureOut.Value, @"\d*\.*\d+");
::::: //}
     output = Regex.Replace(output,captureOut.Value, Function1);
}
// i change the value of pattern based on the output of function 1

在我的代码的这一部分,我不知道为什么
capture out.value
不起作用。

只有在正则表达式中有组时,使用capture属性才有意义,即正则表达式的部分包含在()中。
由于您的正则表达式没有,因此只有一个捕获的组,并且它是与正则表达式匹配的整个字符串。

您能否重新澄清您试图执行的操作?也许可以提供一些输入字符串的示例,以及您希望结果是什么?