C# 正则表达式提取特定宪章之间的文本

C# 正则表达式提取特定宪章之间的文本,c#,regex,C#,Regex,我有下面的字符串作为输入 金额为500.00美元的抵押贷款,日期为2018年7月1日 在输出中,我只希望 500美元 我试过使用下面的正则表达式,但不起作用 Regex = new Regex(@"the amount of \$(.*)", RegexOptions.Singleline) 谁能告诉我我做错了什么 使用上面的正则表达式,我已经得到了日期为2019年7月1日的输出值500.00 但是我只想要$500.00作为输出。使用\$\d+?:\。\d+?并循环所有匹配项: cstring

我有下面的字符串作为输入

金额为500.00美元的抵押贷款,日期为2018年7月1日

在输出中,我只希望

500美元

我试过使用下面的正则表达式,但不起作用

Regex = new Regex(@"the amount of \$(.*)", RegexOptions.Singleline)
谁能告诉我我做错了什么

使用上面的正则表达式,我已经得到了日期为2019年7月1日的输出值500.00

但是我只想要$500.00作为输出。

使用\$\d+?:\。\d+?并循环所有匹配项:

cstring value = "Mortgage (\"Mortgage\") in the amount of $500.00, dated July 1, 2018 herewith";
MatchCollection matches = Regex.Matches(value, @"\$\d+(?:\.\d+)?");
foreach (Match match in matches)
{
    Console.WriteLine(match.Value);
}

\$\d++.\d+应该可以工作。检查此示例:@MarTin该模式至少需要3个字符,例如,也将匹配$1Q1@MarTin此外,您建议的参数将匹配示例中未将新正则表达式分配给变量的字符串,如$500A123。
string str=@" Mortgage (""Mortgage"") in the amount of $500.00, dated July 1, 2019 herewith ";
Regex rg = new Regex(@"the amount of \$(.*), dated ", RegexOptions.Singleline);
//@"\$\d+(?:\.\d+)?"
var ans = rg.Match(str).Groups.Cast<Group>().Skip(1).Select(o => o.Value.Replace("\n", "").Trim());