#_author:Administrator
#date:2019/11/9
#前面的 * + ? 都是贪婪匹配,如果要最少匹配的话,则在后面加 ?
import re
#1.贪婪匹配
ret=re.findall('star*','starrrrrr')
print(ret)# ['starrrrrr']
#2.惰性匹配
ret1=re.findall('star*?','starrrrrr')
print(ret1)# ['sta']
# 3 [] 字符集补充
ret2=re.findall('a[cd]b','acdb')
print(ret2)# [] 因为 c 和 d之间是或者的关系,只能取一个 ret3=re.findall('a[c,d]b','a,b')
print(ret3)# ['a,b']
#4.命名分组,组之间可以用任何符号代替
ret4=re.search('(?P<name>\w{2})/(?P<age>\d{2})','gsjsd/67js9')
print(ret4.group()) # sd/67
print(ret4.group('age'))# 67
print(ret4.group('name')) # sd
# 5.
ret5=re.findall('www.\w+.com','www.jingdong.com')
print(ret5)# ['www.jingdong.com'] ret5_=re.findall('www.(\w+).com','www.jingdong.com')
print(ret5_)# ['jingdong'] findall() 只会把匹配到的组里面的内容取出来
# ?: 取消组的优先级 ret6=re.findall('www.(?:\w+).com','www.jingdong.com')
print(ret6) # ['www.jingdong.com']
# 6.sub()
ret7=re.sub('\d','star','jjsdbs8cbsjds9bjjsnj2fds')
print(ret7)# jjsdbsstarcbsjdsstarbjjsnjstarfds
ret8=re.sub('\d','star','1s466c7',)# 后面加数字代表前面多少个进行替换
print(ret8) # stars466c7
#7.subn() 会返回替换了多少次
ret9=re.subn('\d','asd','sh8sd6sds7smm3ssx')
print(ret9)# ('shasdsdasdsdsasdsmmasdssx', 4)
#8.finditer()
ret10=re.finditer('\d','sdjs7sdvhsb8sbs2bsnmxs9j')# ret10为一个迭代器
print(ret10)# <callable_iterator object at 0x01037490>
print(next(ret10).group())
print(next(ret10).group())
print(next(ret10).group())
print(next(ret10).group())

re模块补充的更多相关文章

  1. 文成小盆友python-num7 -常用模块补充 ,python 牛逼的面相对象

    本篇内容: 常用模块的补充 python面相对象 一.常用模块补充 1.configparser模块 configparser 用于处理特定格式的文件,起内部是调用open()来实现的,他的使用场景是 ...

  2. python模块补充

    一.模块补充 configparser 1.基本的读取配置文件 -read(filename) 直接读取ini文件内容 -sections() 得到所有的section,并以列表的形式返回 -opti ...

  3. python_9(模块补充)

    第1章 re模块补充 1.1 贪婪匹配:回溯算法 1.2 .*?的用法 1.3 例:分组<name>取值 1.4 匹配整数删除小数 1.5 正则测试地址 第2章 重点模块 2.1 hash ...

  4. 8.6 day27 网络编程 osi七层协议 Time模块补充知识 TCP协议

    Time模块补充知识 date和datetime区别是什么? date 就是年月日 datetime就是年月时时分秒 以下代码为什么会报错? import json from datetime imp ...

  5. os模块补充以及序列化模块

    os模块补充以及序列化模块   一.os模块的补充 1.os.path.abspath 能把存在的相对路径的绝对路径显示出来 path = os.path.abspath("连达day19. ...

  6. python day 8: re模块补充,导入模块,hashlib模块,字符串格式化,模块知识拾遗,requests模块初识

    目录 python day 8 1. re模块补充 2. import模块导入 3. os模块 4. hashlib模块 5. 字符串格式:百分号法与format方法 6. 模块知识拾遗 7. req ...

  7. pandas模块补充

    数据分析模块pandas和matplotlib补充 面向百度式编程 面向百度式工作 遇到没有见过的知识点或者是相关知识点一定不要慌,结合百度和已知的知识点去学习 pandas模块补充 基于numpy构 ...

  8. re模块补充与其他模块介绍

    注:昨日写了re单个模块几个重要的点需要补充 一.re模块补充 1.findall独有的优先级别展示 res = re.findall('abc', 'abcabcabcabc') print(res ...

  9. python之re模块补充和其他模块(collection、time、queue、datetime、random)

    目录 re模块补充说明 collections模块 queue模块 time模块 datetime模块 random模块 re模块补充说明 在正则表达式中,'()'的作用是进行分组,但是在re模块中, ...

  10. 7.python模块补充

    此文章是对上节文章模块的补充 一,xml模块 xml是实现不同语言或程序之间进行数据交换的协议,可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言.xml的格式如下 ...

随机推荐

  1. gvim 安装YouCompleteMe插件

    可以参考:YouCompleteMe#full-installation-guide 可以直接下载: http://pan.baidu.com/s/1dDIq2Al 密码: si5q 确保vim支持p ...

  2. js对象属性值初始化封装函数

    在平常做项目的过程中,总是会遇到需要对一个已经定义过的对象的属性值进行初始化,且对象的属性值的类型有多种(string.number.array.object.boolean),为了方便自己就简单封装 ...

  3. 【POJ】3278 Catch That Cow

    题目链接:http://poj.org/problem?id=3278 题意:有一头奶牛跑到了K的位置,农夫在N的位置,求最短抓到奶牛的时间. 农夫有两种移动方式. 1.步行:一分钟内从x->x ...

  4. (一)hello word

    1.在如图demo文件夹下可以编写自己的后端代码. 我们编写hello的接口代码如下: @RestController @RequestMapping("/hello") @Slf ...

  5. asp.net core2.0 依赖注入 AddTransient与AddScoped的区别 - 晓剑 - CSDN博客

    原文:asp.net core2.0 依赖注入 AddTransient与AddScoped的区别 - 晓剑 - CSDN博客 原文地址:http://www.tnblog.net/aojiancc2 ...

  6. Nginx常用功能配置二

    Nginx常用功能配置二 Nginx location匹配设置 location作用:可以根据用户请求的URI来执行不同的应用,根据用户请求的网站的地址URL匹配. location语法: locat ...

  7. 如何通过SVN管理好代码

    来自:http://blog.csdn.net/baronyang/article/details/6942434 ------------------------------------------ ...

  8. luaj使用 方法签名规则 Cocos2dxLuaJavaBridge

    function AndroidHandler:getParamJson()     local args = {nil}     local ok,ret = luaj.callStaticMeth ...

  9. HTML样式链接到外部样式表

    w3cschool链接:http://www.w3school.com.cn/html/html_css.asp <html> <head><link rel=" ...

  10. 时间 '2018-08-06T10:00:00.000Z' 格式转化为本地时间(转)

    原文:https://blog.csdn.net/sxf_123456/article/details/81582964 from datetime import datetime,timedelta ...