import re
'''
其中?P可以理解为将字符串s分组处理并命名为province、city、block
'''
s = '13g00x21yy'
res = re.search('(?P<province>\d{2}).*(?P<city>\d{2}).*(?P<block>\d{2}).*',s)
print(res.groupdict())
"""
运行结果
{'province': '13', 'city': '00', 'block': '21'}
"""
import re
'''
其中?P可以理解为将字符串s分组处理并命名为province、city、block
'''
s = '13g00x21yy'
res = re.search('(?P<province>\d{2}).*(?P<city>\d{2}).*(?P<block>\d{2}).*',s)
print(res.groupdict())
"""
运行结果
{'province': '13', 'city': '00', 'block': '21'}
"""