This commit is contained in:
2509165003
2026-04-02 16:01:37 +08:00
parent bf952bb3aa
commit 1e73b5f504
2 changed files with 15 additions and 0 deletions

15
4.2作业.py Normal file
View File

@@ -0,0 +1,15 @@
import re
phone_book = '''
张三138-1999-9101
李四139-1998-5678
王五138-1997-1234
'''
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)