标签:
#!/usr/bin/env python # -*- coding:utf-8 -*- import re ip_str = "asdad1.1.1.1sdfwe2.6.5.7sdfsf2.3.94.5sdf200.198.25.0" res = [] for i in range(1): ip_t = True m_ind = 0 while ip_t: m = re.search(r"(((2([0-4]\d|5[0-5])|((1\d|[1-9])?\d)|\d)\.){3}(2([0-4]\d|5[0-5])|(1\d|[1-9])?\d|\d))",ip_str[m_ind:]) if m: msum = m.group() res.append(msum) m_ind = ip_str.index(msum) + len(msum) -1 else: ip_t = False print(res) #print(msum,m_ind)
图片有错误,但思路正确,代码和图片对比,放这个是为了对比思路,赞这个图片的人的思路,着实牛
标签:
原文地址:http://www.cnblogs.com/renfanzi/p/5634561.html