zoukankan      html  css  js  c++  java
  • re.groups取出来的空元祖??

    源自学习笔记: day23_1_re_

    groups方法取出来的字符是空的元组??为啥?

    
    '''
    # ------------------------------------------------------------
    # # 6、re.search.group 与 groups
    # # # group(num=0)	匹配的整个表达式的字符串,group() 可以一次输入多个组号,
    # # # 在这种情况下它将返回一个包含那些组所对应值的元组。
    # # # 
    # # # groups()	返回一个包含所有小组字符串的元组,从 1 到 所含的小组号。
    # ------------------------------------------------------------
    '''
    
    import re
    
    a0 = re.search("d", "asfd22af33asf555")
    a1 = re.search("d+", "asfd22af33asf555")
    a2 = re.search("d+", "asfdqwresfad")
    a3 = re.search("d[5]", "asfd22af33asf555")
    print(a0.group(),type(a0.group()))
    print(a1.group())
    # # print(a2.group())     # 报错,因为匹配不到,返回的是None,因此无法来取值
    print(a3.group())
    
    
    print(a0.groups())
    print(a1.groups())
    # # print(a2.groups())     # 报错,因为匹配不到,返回的是None,因此无法来取值
    print(a3.groups())
    
    # D:Anaconda3python.exe D:/C_cache/py/day23-re_logging_hashlib_MoKuaiDaoRu/day23_1_re_.py
    # 2
    # 22
    # 55
    # ()
    # ()
    # ()
    #
    # Process finished with exit code 0
    
    
    
  • 相关阅读:
    深入PHP内核之全局变量
    关于PHP中的opcode
    深入PHP内核之opcode handler
    virtual memory exhausted: Cannot allocate memory
    Nginx配置error_page 404错误页面
    PHP 与 UTF-8
    define() vs const 该如何选择?
    CentOS安装配置Samba
    当···时发生了什么?
    PHP中curl的使用
  • 原文地址:https://www.cnblogs.com/jyfootprint/p/9442007.html
Copyright © 2011-2022 走看看