C# 正则表达式例子
单独匹配
string text = "订单号: 12345, 数量: 8, 价格: 99";
MatchCollection matches = Regex.Matches(text, @"\d+");
foreach (Match m in matches)
{
Console.WriteLine(m.Value);
}
// 输出:
// 12345
// 8
// 99.5带子成员
string lrcLine = "[无尽的华尔兹1][无尽的华尔兹2]";
MatchCollection matches = Regex.Matches(lrcLine, @"\[(.*?)\]");
foreach (Match m in matches)
{
Console.WriteLine("成员");
Console.WriteLine($"{m.Groups[0].Value}");
Console.WriteLine($"子成员");
Console.WriteLine($"{m.Groups[1].Value}");
Console.WriteLine( "--------");
}
// 输出:
//成员
//[无尽的华尔兹1]
//子成员
//无尽的华尔兹1
//--------
//成员
//[无尽的华尔兹2]
//子成员
//无尽的华尔兹2
//--------转载请注明出处。