首页 > 其他 > 详细

10Match方法的属性和方法

时间:2020-05-30 01:54:36      阅读:44      评论:0      收藏:0      [点我收藏+]
"""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)

10Match方法的属性和方法

原文:https://www.cnblogs.com/sruzzg/p/12990235.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!