re.sub(patern,repl,string,count,flags=0)
用于实现对字符串中指定字符串的替换
re.split(pattern,string,maxsplit,flags=0)
字符串中的split()方法功能相同,都是分隔字符串
import re
pattern='黑客|破解|反爬'
s='我想学习python,想破解一些VIP视频,Python可以实现无底线反爬吗?'
new_s=re.sub(pattern,'XXX',s)
print(new_s)
s2='https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1'
pattern2='[?|&]'
lst=re.split(pattern2,s2)
print(lst)
?