请帮助提取[SUM]的regex结果
[4]
[4]
[6]
[6]
[8]
[8]
[10]
[10]
[SUM] 0-10.01 sec 5.70 GBytes 4.89 Gbits/sec sender
[SUM] 0-10.01秒5.69 GBytes 4.88 Gbits/秒接收
帮助获取[SUM]发送方和接收方Gbits/sec
最后2行- Gbits/sec
例如来获取
first = 4.89
秒= 4.88
i tried regex - ([SUM])。* gb) ? (gbit/秒。*接收器)由于
您必须转义正则表达式中的特殊字符([,/)。
string data = @"
[ 4] 0.00-10.01 sec 1.32 GBytes 1.13 Gbits/sec sender
[ 4] 0.00-10.01 sec 1.32 GBytes 1.13 Gbits/sec receiver
[ 6] 0.00-10.01 sec 1.56 GBytes 1.34 Gbits/sec sender
[ 6] 0.00-10.01 sec 1.56 GBytes 1.34 Gbits/sec receiver
[ 8] 0.00-10.01 sec 1.52 GBytes 1.31 Gbits/sec sender
[ 8] 0.00-10.01 sec 1.52 GBytes 1.31 Gbits/sec receiver
[ 10] 0.00-10.01 sec 1.29 GBytes 1.11 Gbits/sec sender
[ 10] 0.00-10.01 sec 1.29 GBytes 1.11 Gbits/sec receiver
[SUM] 0.00-10.01 sec 5.70 GBytes 4.89 Gbits/sec sender
[SUM] 0.00-10.01 sec 5.69 GBytes 4.88 Gbits/sec receiver";
var matches = System.Text.RegularExpressions.Regex.Matches(data, @"[SUM].*s(?<rate>[0-9.]+) Gbits/sec (?<type>sender|receiver)");
foreach (System.Text.RegularExpressions.Match m in matches)
{
Console.WriteLine($"{m.Groups["rate"].Value} {m.Groups["type"].Value}");
}
输出4.89 sender
4.88 receiver