如何使用python搜索列表中的任何数字出口

时间:2018-01-09 11:07:15

标签: python paramiko

我正在尝试搜索列表中的任何IP。 下面是字符串列表,从这个列表我想搜索是否存在任何使用python的IP。

[
   'Neighbour', 
   'Information:', 
   'Chassis', 
   'type', 
   ':', 
   'Mac', 
   'address', 
   'address'
   ' :'
   '146.89.4.32'
]

1 个答案:

答案 0 :(得分:1)

使用正则表达式。

Please check this link for more info on regex !!!

More info how below regex works !!!

import re
val = ['Neighbour', 'Information:', 'Chassis', 'type', ':', 'Mac', 'address', 'Address', ':', '146.89.4.32']

for v in val:
    temp = re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',v)
    if len(temp) !=0:
        print v
相关问题