一个刚结束的笔试题目,简单贴一下吧,下面是具体实现:
#!usr/bin/env python #encoding:utf-8 ''' __Author__:沂水寒城 功能:判断一个字符串是否是合法IP地址 ''' import re def judge_legal_ip(one_str): ''' 正则匹配方法 判断一个字符串是否是合法IP地址 ''' compile_ip=re.compile('^((25[0-5]|2[0-4]\d|[01]"color: #ff0000">结果如下:is not a legal ip address! 172.31.137.251 is a legal ip address! 100.10.0.1000 is not a legal ip address! 1.1.1.1 is a legal ip address! 12.23.13 is not a legal ip address! aa.12.1.2 is not a legal ip address! 12345678 is not a legal ip address! 289043jdhjkbh is not a legal ip address!以上这篇python实现判断一个字符串是否是合法IP地址的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。