import re
with open('file.txt', 'r') as file:
f = file.read().splitlines()
for line in f:
found = re.findall(r'(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})', line)
for f in found:
print(f)
编辑:
我们打开txt并逐行读取,然后使用正则表达式为每行查找IP(可以有1-3个数字,然后)。重复4次)
网友
2楼 ·
发布于 2024-06-26 10:22:44
使用正则表达式和字符串操作:
import re
s = '''My Address: 10.10.10.1
Explicit Route: 192.168.238.90 192.168.252.209 192.168.252.241 192.168.192.209
192.168.192.223
Record Route:'''
ips = re.findall(r'\d+\.\d+\.\d+\.\d+', s[s.find('Explicit Route'):s.find('Record Route')])
编辑:
我们打开txt并逐行读取,然后使用正则表达式为每行查找IP(可以有1-3个数字,然后)。重复4次)
使用正则表达式和字符串操作:
相关问题 更多 >
编程相关推荐