zoukankan      html  css  js  c++  java
  • 10Match方法的属性和方法

    """Match方法的属性和方法"""


    """
    Match方法的属性和方法
    """
    import re

    match_obj = re.compile(r'(d+)-(?P<sec>d+)').match('010-123456789', 1, 7)
    # <re.Match object; span=(1, 7), match='10-123'>
    print(match_obj)

    print(match_obj.string) # 010-123456789
    print(match_obj.re) # re.compile('(\d+)-(?P<sec>\d+)')
    print(match_obj.pos) # 1
    print(match_obj.endpos) # 7
    print(match_obj.lastindex) # 2
    print(match_obj.lastgroup) # sec

    print(match_obj.group(2)) # 123
    print(match_obj.group('sec')) # 123
    print(match_obj.group()) # 10-123
    print(match_obj.group(0)) # 10-123
    print(match_obj.group(1, 2)) # ('10', '123')

    print(match_obj.groups()) # ('10', '123')
    print(match_obj.groupdict()) # {'sec': '123'}
    print(match_obj.start('sec')) # 4
    print(match_obj.start()) # 1
    print(match_obj.end()) # 7
    print(match_obj.span()) # (1, 7)
  • 相关阅读:
    推导式
    解构
    for 循环
    运算符
    while 循环
    流程控制语句
    索引和切片
    ASC转换BCD,ASC2BCD(转)
    CString和char互转,十六进制的BYTE转CString
    C++添加简单的日记记录
  • 原文地址:https://www.cnblogs.com/sruzzg/p/12990235.html
Copyright © 2011-2022 走看看