正则模块,用sub方法,替换匹配到的子串
content = 'hello 12345, hello 456321' pat = re.compile(r'\d+')#要替换掉的部分 m = pat.sub("666", content) print(m)
输出为:
hello 666, hello 666