上传文件至 /
This commit is contained in:
18
text4.py
Normal file
18
text4.py
Normal 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)
|
||||
Reference in New Issue
Block a user