Python 正则表达式(直接转化为dict)
import re
s = '1102231990xxxxxxxx'
res = re.search('(?P<province>\d{3})(?P<city>\d{3})(?P<born_year>\d{4})',s)
print(res.groupdict())
# 结果:{'province': '110', 'city': '223', 'born_year': '1990'}
import re
s = '1102231990xxxxxxxx'
res = re.search('(?P<province>\d{3})(?P<city>\d{3})(?P<born_year>\d{4})',s)
print(res.groupdict())
# 结果:{'province': '110', 'city': '223', 'born_year': '1990'}