正则 不匹配某个单词

import re
skip_word = 'hede'
stranger_char = '虩'
content = '''hoho
hihi
haha
hede'''
print(
    '\n'.join(re.findall(
        '([^{}]*?)\n'.format(stranger_char),
        content.replace(skip_word, stranger_char)
    )).replace(stranger_char, skip_word)
)

# hoho
# hihi
# haha
posted @ 2021-11-05 14:04  twfb  阅读(185)  评论(0编辑  收藏  举报