4.2
This commit is contained in:
15
4.2作业.py
Normal file
15
4.2作业.py
Normal 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)
|
||||
Reference in New Issue
Block a user