我现在需要匹配list中的所有未x.x.x.1的IP地址,这个我不知道怎么搞,我想到的就是用正则匹配,小弟正则不是很懂,有大佬能帮忙看一下吗
import re
key = r"saas and sas 192.168.1.128and saaas"
p1 = r"[0-2]d?.[0-2]d?.[0-2]d*?.d{1,3}" #192.168.1.1数字加点判断
pattern1 = re.compile(p1)
print(pattern1.findall(key))
string = 'asa255.245.99.250wewewe'
p1="((25[0-5]|2[0-4]d|[0-1]?d?d)(.(25[0-5]|2[0-4]d|[0-1]?d?d)){3})" #最终的结果
pattern1 = re.compile(p1)
print(pattern1.findall(string))
4 回答4.5k 阅读✓ 已解决
1 回答3.3k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.9k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
简陋版~, 对于
ip
的合法性没有做匹配, 仅仅匹配符合x.x.x.1