替换 sub()
上一节
下一节
替换
sub(pattern, repl, string, count=0, flags=0)
import re
change=re.sub('\d+','!','py1th22on')
print(change)
结果:py!th!on
import re
change=re.sub('\d+','!','py1th22on',count=1)
print(change)
结果:py!th22on
import re
change=re.subn('\d+','!','py1th22on333',count=2)
print(change)
结果:('py!th!on333', 2)
结果是元组类型

