liyingchunvip 发表于 2014-06-21 13:13

求助大神,初学re

我的一个文件里的内容
ProtocolAddress          Age (min)Hardware Addr   Type   Interface
Internet10.33.96.15         101   001b.21c7.a519ARPA   Vlan96Connection to 10.33.96.200 closed by remote host.
Connection to 10.33.96.200 closed.

现在需要把mac地址扣出来,求大神指点,谢谢

liyingchunvip 发表于 2014-06-21 14:25

快沉了,求大神 :'(

whitelotus19 发表于 2014-06-21 15:01

这样可以吗?import re

text='''
ProtocolAddress          Age (min)Hardware Addr   Type   Interface
Internet10.33.96.15         101   001b.21c7.a519ARPA   Vlan96Connection to 10.33.96.200 closed by remote host.
Connection to 10.33.96.200 closed.
ProtocolAddress          Age (min)Hardware Addr   Type   Interface
Internet10.33.96.15         101   1234.21c7.abcdARPA   Vlan96Connection to 10.33.96.200 closed by remote host.
Connection to 10.33.96.200 closed.
'''
pat='{4}\.{4}\.{4}'
for match in re.findall(pat,text):
    print match

liyingchunvip 发表于 2014-06-21 15:18

回复 3# whitelotus19


    大神就是大神,灰常谢谢.
页: [1]
查看完整版本: 求助大神,初学re