python ip正则式
所属分类:
脚本专栏 / python
阅读数:
1540
收藏 0赞 0分享
ip正则式为:r'(([12][0-9][0-9]|[1-9][0-9]|[1-9])\.){3,3}([12][0-9][0-9]|[1-9][0-9]|[1-9])'
以下为一个示例
#-*- coding:utf-8 -*-
import re
def ip():
'验证IP的正则式'
def match_group(p):
s = '''211.210.209.108
gan ffad1.210.2.108
d ffad1.210.2.109afa'''
com = re.compile(p)
lst_m = com.finditer(s)
for m in lst_m:
print m.group()
p = r'(([12][0-9][0-9]|[1-9][0-9]|[1-9])\.){3,3}([12][0-9][0-9]|[1-9][0-9]|[1-9])'
match_group(p)
def group():
'''若存在多个匹配,可以用finditer来获取到多个组'''
def match(p):
s = 'Isaac Newton, physicist, huang zhijun'
mo = re.compile(p)
m = mo.search(s)
if not m:
print 'no match'
else:
print mo.findall(s)
print 'm.group(0):', m.group(0)
# print 'm.group(1):', m.group(1)
# print 'm.group(2):', m.group(2)
m_ite = mo.finditer(s)
for ite in m_ite:
print 'ite.group(0)', ite.group(0)
print 'ite.group(1)', ite.group(1)
print 'ite.group(2)', ite.group(2)
# p = r'(\w+) (\w+)'
p = r'(\w+) (\w+)'
match(p)
if __name__ == '__main__':
ip()
# group()
深入源码解析Python中的对象与类型
这篇文章主要介绍了深入源码解析Python中的对象与类型,涉及到对象的引用计数方法和类型的定义等深层次内容,需要的朋友可以参考下
收藏 0赞 0分享
Python实时获取cmd的输出
本文给大家分享python实时获取cmd的输出,对python实时获取输出相关知识感兴趣的朋友一起学习吧
收藏 0赞 0分享
分享Python字符串关键点
字符串是 Python 中最常用的数据类型。我们可以使用引号来创建字符串,通过本篇文章给大家分享python字符串关键点相关资料,感兴趣的朋友一起学习吧
收藏 0赞 0分享
十个Python程序员易犯的错误
不管是在学习还是工作过程中,人都会犯错。虽然Python的语法简单、灵活,但也一样存在一些不小的坑,一不小心,初学者和资深Python程序员都有可能会栽跟头。本文为大家分享了10大常见错误,需要的朋友可以参考下
收藏 0赞 0分享
在DigitalOcean的服务器上部署flaskblog应用
这篇文章主要介绍了在DigitalOcean的服务器上部署flaskblog的方法,flaskblog是用Python的Flask开发的一个博客程序,而DigitalOcean则是大受欢迎的SSD主机提供商,需要的朋友可以参考下
收藏 0赞 0分享
查看更多