zoukankan      html  css  js  c++  java
  • re正则表达式公式讲解5

    1.refullmatch() 完全匹配字符串则返回object,否则返回None

    import re
    
    s = "max@123uyt146"
    
    print(re.fullmatch("w+@w+",s))
    
    # <_sre.SRE_Match object; span=(0, 13), match='max@123uyt146'>
    

    2.re.compile()  

    两种方法返回的同一个对象,有什么区别?

    compile()时先编译好,再匹配,如果需要匹配的字符串多的话能省很多时间。

    fullmatch(patterns,str)  一边编译一遍匹配,如果只有一个字符串,compile和fullmatch没区别,如果字符串多的话,compile比fullmatch好。

    import re
    
    s = "max@123uyt146"
    
    pattern = re.compile("w+@w+")
    
    print(pattern.fullmatch(s))
    
    # <_sre.SRE_Match object; span=(0, 13), match='max@123uyt146'>
    
    print(re.fullmatch("w+@w+",s))
    
    # <_sre.SRE_Match object; span=(0, 13), match='max@123uyt146'>
    

      

      

  • 相关阅读:
    python之map,filter
    python函数的闭包
    Hibernate查询对象的方法浅析
    底部浮动
    DataGrid-自定义排序
    DataGrid-1
    Alert
    2014-01-04 SQL练习
    proguard-gui 混淆代码简要笔记
    vim利用coc补全的配置过程
  • 原文地址:https://www.cnblogs.com/Roc-Atlantis/p/8918629.html
Copyright © 2011-2022 走看看