import sys
import re
if __name__=='__main__':
    it=iter(sys.stdin)
    while 1:
        try:
            line=next(it).strip()
            old=next(it).strip()
            pattern='\\b('+old+')\\b'
            new=next(it).strip()
            def repl(obj):
                if obj.group(1) is not None:
                    return new
            ans=re.sub(pattern,repl,line)
            print(ans)
        except:
            break

使用正则表达式进行替换,将待替换单词精准提取出分组,直接替换分组