mirror of
https://github.com/hyb-oyqq/FRAISEMOE-Addons-Installer-NEXT.git
synced 2025-12-21 06:18:36 +00:00
17 lines
471 B
Python
17 lines
471 B
Python
|
|
import re
|
|||
|
|
|
|||
|
|
def censor_url(text):
|
|||
|
|
"""Censors URLs in a given text string, replacing them with a protection message.
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
text: 要处理的文本
|
|||
|
|
|
|||
|
|
Returns:
|
|||
|
|
str: 处理后的文本,URL被完全隐藏
|
|||
|
|
"""
|
|||
|
|
if not isinstance(text, str):
|
|||
|
|
text = str(text)
|
|||
|
|
|
|||
|
|
# 匹配URL并替换为固定文本
|
|||
|
|
url_pattern = re.compile(r'https?://[^\s/$.?#].[^\s]*')
|
|||
|
|
return url_pattern.sub('***URL protection***', text)
|