替换 unicode 中的多个字符 python

Replacing more than one character in unicode python

import re
test = unicode("شدَد", encoding='utf-8')
test = test.replace(u"\u064e", "")

这是删除一个字符的代码。我想用 0627 替换以下任何 unicode 字符:0622、0623、0625。这是针对阿拉伯语的。我知道如何在多行中完成,但有没有办法在一行中完成?

如果要替换多个字符(unicode 代码点)in a oneliner,您可以使用简单的交替 regex:

import re
test = unicode("شدَد", encoding='utf-8')
test = re.sub(u"\u064e|\u0634", "", test,  flags=re.UNICODE)

或者,使用范围正则表达式:

test = re.sub(u"[\u064e\u0634]", "", test,  flags=re.UNICODE)