import re pattern = r'h(e|r|t)' string = "我是一名he,我看见ht打人,我也是给hr人" match = re.sub(pattern,"@@",string) print(match)