我正在尝试解析这个ifconfig输出。我看到了另一个堆栈溢出的例子,他们做了同样的代码,但它创建了一个嵌套列表。但是当我做同样的事情时,我只得到第一个匹配选项。另外,我想把RX和TX包添加到列表中,这似乎不起作用。在
Ifconfig输出
Mg0_RSP0_CPU0_0 Link encap:Ethernet HWaddr 70:e4:22:32:53:42
inet addr:20.200.130.1 Mask:255.255.0.0
inet6 addr: fe80::72e4:22ff:fe32:5342/64 Scope:Link
UP RUNNING NOARP MULTICAST MTU:1514 Metric:1
RX packets:147918 errors:0 dropped:0 overruns:0 frame:0
TX packets:119226 errors:0 dropped:0 overruns:0 carrier:3
collisions:0 txqueuelen:1000
RX bytes:103741434 (98.9 MiB) TX bytes:5320623 (5.0 MiB)
Tg0_0_0_7_0 Link encap:Ethernet HWaddr 78:ba:f9:35:66:46
inet addr:13.13.13.1 Mask:255.255.255.0
inet6 addr: fe80::7aba:f9ff:fe35:6646/64 Scope:Link
UP RUNNING NOARP MULTICAST MTU:1514 Metric:1
RX packets:26 errors:0 dropped:0 overruns:0 frame:0
TX packets:5058 errors:0 dropped:0 overruns:0 carrier:3
collisions:0 txqueuelen:1000
RX bytes:1832 (1.7 KiB) TX bytes:454625 (443.9 KiB)
脚本
^{pr2}$
好吧,我测试过你的代码,刚开始有一个结果,第二个结果是:
然后,我仔细查看了正则表达式中的内容,似乎您可能在第二段之前有额外的新行,就像我在第一段之前那样,从而导致\S停止。你可以用(如果我对你得到单一结果的原因是正确的话)用添加\s?要开始正则表达式:
^{pr2}$或者,如果是简单接口和IP检索,您可以使用更简单、更快的拆分…
如果有人好奇,我甚至会计时:
结果
有人想加入Python3.5吗?在
嗯,奇怪的是没有结论。在
你的测量不正确。在函数中调用
ma.match(paragraph)
两次。在Python 3.7.1(v3.7.1:260ec2c36a,2018年10月20日,03:13:28)
拆分0.569942316
雷克斯38852
相关问题 更多 >
编程相关推荐