题解 | #字符串字符匹配#
牛客网的IP地址
http://www.nowcoder.com/practice/b4159a20aefa406aaa1bfd7d9739c70c
import re
a=input()
if a[-1]=='.': #这四种if都是排错的
print('illegal')
exit()
if len(a)<7:
print('illegal')
exit()
if ':' in a:
print('illegal')
exit()
if a.count('.')>=4:
print('illegal')
exit()
b=re.findall('\d+',a) #正则表达式
for i in b:
if int(i)<0 or int(i)>255:
print('illegal')
exit()
print('legal')
a=input()
if a[-1]=='.': #这四种if都是排错的
print('illegal')
exit()
if len(a)<7:
print('illegal')
exit()
if ':' in a:
print('illegal')
exit()
if a.count('.')>=4:
print('illegal')
exit()
b=re.findall('\d+',a) #正则表达式
for i in b:
if int(i)<0 or int(i)>255:
print('illegal')
exit()
print('legal')