• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python ip正则式

python ip正则式

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 正则匹配ip,python ip,python ip转换,python ip池,python tcp/ip等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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 ip正则式

相关文章

  • 用Python的urllib库提交WEB表单
  • 400多行Python代码实现了一个FTP服务器
  • Python urllib模块urlopen()与urlretrieve()详解
  • python逐行读取文件内容的三种方法
  • python常用知识梳理(必看篇)
  • Python IDE PyCharm的基本快捷键和配置简介
  • pyqt4教程之messagebox使用示例分享
  • python之yield表达式学习
  • Pthon批量处理将pdb文件生成dssp文件
  • python计算一个序列的平均值的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python类继承用法实例分析
    • 归纳整理Python中的控制流语句的知识点
    • Django接受前端数据的几种方法总结
    • python 统计代码行数简单实例
    • python实现简单温度转换的方法
    • Pycharm学习教程(5) Python快捷键相关设置
    • Python的Bottle框架中实现最基本的get和post的方法的教程
    • 10款最好的Web开发的 Python 框架
    • 详解Python中的正则表达式的用法
    • Python中的匿名函数使用简介

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有