这是我的代码:
s="""
[ 8] 0.00-34.53 sec 0.00 Bytes 0.00 bits/sec receiver
[SUM] 0.00-34.53 sec 2.11 GBytes 624 Mbits/sec sender
[ 12] 0.00-34.53 sec 0.00 Bytes 0.00 bits/sec receive
[SUM] 0.00-34.75 sec 0.00 Bytes 0.00 bits/sec sender
[SUM] 0.00-34.53 sec 2.11 GBytes 824 Mbits/sec sender
[SUM] 0.00-34.75 sec 0.00 Bytes 0.00 bits/sec sender
"""
items=re.findall("^.[SUM].*sender",s,re.MULTILINE)
for x in items:
print(x)
这给出了输出:
[SUM] 0.00-34.53 sec 2.11 GBytes 624 Mbits/sec sender
[SUM] 0.00-34.53 sec 2.11 GBytes 824 Mbits/sec sender
[SUM] 0.00-34.75 sec 0.00 Bytes 0.00 bits/sec sender
[SUM] 0.00-34.75 sec 0.00 Bytes 0.00 bits/sec sender
但我想获得以下输出,它以字符串 [SUM] 开头并以字符串 sender 结尾,并且不应显示具有任何 0.00 字节和 0.00 位/秒的行
[SUM] 0.00-34.53 sec 2.11 GBytes 624 Mbits/sec sender
[SUM] 0.00-34.53 sec 2.11 GBytes 824 Mbits/sec sender