脱敏电话号码和身份证号
import re
def check_phone_sfz_chuli(data):
reg = '^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$'
if len(data) == 11 and re.match(reg,data):
return data.replace(data[3:7], "****")
elif len(data) == 18 and data.isdigit(): # 判断是否是身份证
return data.replace(data[8:14], '******')
else:
return data
### 从数据库里捞出来的原始字符串
tt = [(1, 'rose', '18037029723'), (2, 'tom', 'cs'), (3, 'nick', 'gz')]
for line in tt:
l = list(line) # 元组转列表
print(l)