python3 判断字符串是否为IP

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re

ip = "192.168.1.1"

ip = re.findall("^(1d{2}|2[0-4]d|25[0-5]|[1-9]d|[1-9]).(1d{2}|2[0-4]d|25[0-5]|[1-9]d|d).(1d{2}|2[0-4]d|25[0-5]|[1-9]d|d).(1d{2}|2[0-4]d|25[0-5]|[1-9]d|d)$", ip)
print(ip)

if not ip:
    print("no")
else:
    print("yes")
原文地址:https://www.cnblogs.com/37yan/p/10303724.html