//匹配小数
string input = "f57df0.133abc";
Console.WriteLine("原始数据:\n" + input + "\n");
string pattern = @"\d+(\.\d+)?";
//匹配一个,单个结果
Match oneMacth = Regex.Match(input,pattern);
string oneValue = oneMacth.Value; //返回第一个匹配结果
Console.Write("单个匹配结果:\n");
Console.Write(oneValue + "\n");
//匹配多个,多个集合
MatchCollection moreMatch = Regex.Matches(input, pattern);
Console.Write("多个匹配结果:\n");
for (int i = 0; i < moreMatch.Count; i++)
{
string one = moreMatch[i].Value;
Console.Write(one + "\n");
}
Console.ReadKey();
结果如下