如何过滤中文(仅限中文)

Dre*_*puf 7 python

我想将一些包含标点符号和全角符号的文本转换为纯中文文本.

maybe_re = re.compile("xxxxxxxxxxxxxxxxx") #TODO
print "".join(maybe_re.findall("??,?????????.??????"))

# I want out
?????????????
Run Code Online (Sandbox Code Playgroud)

Tho*_*s K 4

我不知道有什么好方法将汉字与其他字母分开,但你可以区分字母和其他字符。使用正则表达式,您可以使用r"\w"re.UNICODE如果您使用的是 Python 2,则使用该标志进行编译)。这将包括数字和字母,但不包括标点符号。

unicodedata.category(c)会告诉你 c 是什么类型的字符。你的中文字母是“Lo”(不区分大小写的字母),而标点符号是“Po”。