正则表达式排除特定模式

时间:2018-04-21 02:34:58

标签: python regex

我正在写一个正则表达式来预处理一些推文。很多时候,我会遇到looovehi等拼写。我正在尝试将它们清理为love w = re.sub(r'[^\w\s]|(.)(?=\1)', '', w) 以清除多个连续字符的使用情况。我的代码如下:

book

这可以完成大部分工作,但它也会清除bokdeepdepoo等字词。我想从此模式中排除eew = re.sub(r'(?!oo)[^\w\s]|(.)(?=\1)', '', "book") 。试过这样做:

const bodyDataAnswer = {
    answers: this.verifyCustomer.questions.map(q => ({
        question_id: q.id,
        int_result: q.answer_template.answers["0"].int_result,
        string_result: q.answer_template.answers["0"].string_result
    }))
};

但是这没用。请帮忙。

1 个答案:

答案 0 :(得分:0)

这个正则表达式怎么样?

[^\w\s]|(.)(?=\1(?<![^o]oo|[^e]ee))

Demo

相关问题