python 正则表达式 替换网址
import re def replace_urls(text): # 匹配http或https网址的正则表达式 url_pattern = re.compile(r'https?://[^\s]+') # 替换网址 return url_pattern.sub('', text) # 示例文本 text = "查看我的网站: https://example.com, 还有我的Github: https://github.com/username" # 替换网址 new_text = replace_urls(text) print(new_text)

浙公网安备 33010602011771号