我正在尝试使用 Python 中的正则表达式从输出中提取几个感兴趣的字段。
假设我的字符串为
Interface1 is down (Administratively down)
我写的正则表达式是:
pat = 'Interface(\d) is (\S)+ (.*)'
我能够获得所需的字段,但是当界面启动时,不会打印原因,我也想让正则表达式为这种情况工作..现在用我写的常规 exp,它似乎不起作用..有人可以帮忙..
当接口(interface)启动时,输出为
Interface1 is Up
m.group()
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
m.group()
AttributeError: 'NoneType' object has no attribute 'group'
最佳答案
关于适用于动态匹配组对象的 Python 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699219/