码迷,mamicode.com
首页 > 其他好文 > 详细

10Match方法的属性和方法

时间:2020-05-30 00:50:16      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:mat   string   upd   dict   group   str   art   属性   ast   

"""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方法的属性和方法

标签:mat   string   upd   dict   group   str   art   属性   ast   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!