"""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)
相关文章: