上传文件至 /

This commit is contained in:
2026-04-02 16:07:32 +08:00
parent e470991d88
commit 304a2c3f51
4 changed files with 79 additions and 0 deletions

18
text4.py Normal file
View File

@@ -0,0 +1,18 @@
import re
phone_book = '''
张三138-1234-5678
李四139-5678-1234
王五138-0000-1111
'''
# 脱敏:将 138-****-5678 格式输出
# 提示:使用分组和 re.sub
pattern = r'(\d{3})-(\d{4})-(\d{4})'
def mask_phone(match):
return f'{match.group(1)}-****-{match.group(3)}'
masked = re.sub(pattern, mask_phone, phone_book)
print(masked)