我有一个字符串,我想使用Regex从整个字符串中提取一个特定的行。
这是我的字符串:
Physical interface: rt90, Enabled, Helical link is Up
Interface index: 178, SPMZ ifIndex: 980
Description: 4&109G LAG to kah7zt84
Link-level type: Ethernet, XCU: 9082, Speed: 10Gbps, BPDU Error: Hello,
Wind-REWRITE Error: None, Loopback: Disabled, Source filtering: abled,
Flow : abled
Pad to min frame size0: Disabled
Minimum li needed: 1, Minimum bandwidth need: 0bps
Device flags : Running
Interface flags: RTYU-Traps Internal: 0x40
Current address: 1e:pb:i0:90:10:76, Hardware address: 1e:pb:i0:90:10:768
Last flapped : 2017-12-16 32:12:12 GMT (3d 16:16 ago)
Input rate : 115 bps (20 pps)
Output rate : 8 bps (1 pps)`
我想提取以下内容:
Physical interface: rt90, Enabled, Helical link is Up
(第一行)
有人可以帮忙吗? 感谢。
答案 0 :(得分:1)
要找到以“物理接口”开头的第一行,您可以使用:
lines = text.splitlines()
for line in lines:
if line.startswith("Physical interface"):
print(line)
break
else:
print('Not found')