正则实现对一段文本同时匹配多个字符串

def asr_to_correct(text):
    rep = dict((re.escape(k), v) for k, v in error_asr_map.items())
    pattern = re.compile("|".join(rep.keys()))
    text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
    return text

 

posted @ 2019-09-09 11:16  cup_leo  阅读(1317)  评论(0编辑  收藏  举报