import re

st = 'asxxixxsaefxxlovexxsdwdxxyouxxde'

#search()和 findall()的区别

a = re.search('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st)
#print(a)
#运行结果
#<_sre.SRE_Match object; span=(2, 30), match='xxixxsaefxxlovexxsdwdxxyouxx'> #group()方法
b = re.search('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st).group(3)
print(b)
#运行结果
#you c = re.findall('xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx',st)
print(c) #结果中列表中包含一个元组,只有待匹配字符串中还有
#'xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx'
#例如:
xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx+++xx(.*?)xxsaefxx(.*?)xxsdwdxx(.*?)xx
#这种格式的才会有不止一个元组

#运行结果
#[('i', 'love', 'you')] print(c[0][2])
#运行结果
#you

python正则表达式02--findall()和search()方法区别,group()方法的更多相关文章

  1. python正则表达式函数match()和search()的区别详解

    match()和search()都是python中的正则匹配函数,那这两个函数有何区别呢? match()函数只检测RE是不是在string的开始位置匹配, search()会扫描整个string查找 ...

  2. Python正则表达式re.findall("[A-Za-z]([A-Za-z0-9])*[.]txt",'Abc2019.txt')的结果为什么是['9']

    在<Python妙用re.sub分析正则表达式匹配过程>中老猿分析了findall函数的返回情况,老猿前一阵子在执行这个语句时: >>> re.findall(" ...

  3. python正则表达式(5)--findall、finditer方法

    findall方法 相比其他方法,findall方法有些特殊.它的作用是查找字符串中所有能匹配的字符串,并以结果存于列表中,然后返回该列表 注意: match 和 search 是匹配一次 finda ...

  4. python re 里面match 和search的区别

    re.match()从开头开始匹配string. re.search()从anywhere 来匹配string. 例子: >>> re.match("c", &q ...

  5. 第11.3节 Python正则表达式搜索支持函数search、match、fullmatch、findall、finditer

    一. 概述 re模块的函数search.match.fullmatch.findall.finditer都是用于搜索文本中是否包含指定模式的串,函数的参数都是一样的,第一个参数是模式串.第二个是搜索文 ...

  6. python re.match与re.search的区别

    re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None:而re.search匹配整个字符串,直到找到一个匹配. #!/usr/bin/python impor ...

  7. Python正则表达式re.findall一个有趣的现象

    下面通过几个案例来分析一下, 注意:本节的parsematch函数请参考<妙用re.sub分析正则表达式解析匹配过程> 案例一: >>> re.findall(r&quo ...

  8. python 正则表达式 re.findall &re.finditer

    语法: findall 搜索string,以列表形式返回全部能匹配的子串 re.findall(pattern, string[, flags]) finditer 搜索string,返回一个顺序访问 ...

  9. Python正则表达式之findall疑点

    在findall中使用()进行分组时,得出的结果会优先提取分组的,比如下面这个例子 In [46]: re.findall(r"www.(baidu|163).com", &quo ...

  10. python 正则表达式教程(转)

    转自:https://zhuanlan.zhihu.com/p/28920775 本节我们看一下正则表达式的相关用法,正则表达式是处理字符串的强大的工具,它有自己特定的语法结构,有了它,实现字符串的检 ...

随机推荐

  1. CSS命名规范(规则)

    常用的CSS命名规则 头:header内容:content/container尾:footer导航:nav侧栏:sidebar栏目:column页面外围控制整体佈局宽度:wrapper左右中:left ...

  2. ArcGisJS的layers-add-result事件总结

    map.on("layers-add-result", initEditing);当地图控件中的所有图层加载完毕之后触发. 注意图层加载完成后返回的的结果:event. funct ...

  3. 仿照everything写的一个超级速查 原创

    http://files.cnblogs.com/files/jacd/%E8%B6%85%E9%80%9F%E6%9F%A5%E6%96%87%E4%BB%B6.zip 速度奇快无比,体积奇小无比, ...

  4. SAP成都研究院Sunshine: 我的C4C实习感受和保研之路

    今天的文章来自SAP成都一位实习生,曾经和Jerry同在C4C成都开发团队一起工作过.在Sunshine最后一个工作日里,Jerry和Sunshine一起吃饭的时候,她曾经聊到接下来的保研打算和将来工 ...

  5. 经典的hash函数

    unsigned int SDBMHash(char *str){    unsigned int hash = 0;     while (*str)    {        // equivale ...

  6. 剑指offer54 表示数值的字符串

    错误的代码: class Solution { public: bool isNumeric(char* string) { if(string == NULL) return false; if(* ...

  7. 机器学习实战之Logistic回归

    Logistic回归一.概述 1. Logistic Regression 1.1 线性回归 1.2 Sigmoid函数 1.3 逻辑回归 1.4 LR 与线性回归的区别 2. LR的损失函数 3. ...

  8. lasagne保存网络参数

    # Optionally, you could now dump the network weights to a file like this: # np.savez('model.npz', *l ...

  9. jQuery选择器与事件学习笔记

    层次选择器:  $("div li")获取div下的所有li元素(后代.子.子的子......)  $("div>li")获取div下的直接li子元素.  ...

  10. Mysql查看锁等信息SQL语句

    查看锁等信息,包括锁信息: select "HOLD:",ph.id h_processid,trh.trx_id h_trx_id,trh.trx_started h_start ...