Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python2.7删除特殊的chac,空格,但不删除中文字符_Python 2.7 - Fatal编程技术网

Python 2.7 Python2.7删除特殊的chac,空格,但不删除中文字符

Python 2.7 Python2.7删除特殊的chac,空格,但不删除中文字符,python-2.7,Python 2.7,结果应为:“特殊字符空间88323kek郭" 我已经试过了 print'。使用和函数连接(c代表字符串中的c。如果u'\u4e00'解决方案,则解码('utf-8'): string = "Special $#! characters spaces 888323 Kek ཌི ༜ 郭 ༜ དྀ " 输出: import re string = "Special $#! characters spaces 888323 Kek ཌི ༜ 郭 ༜ དྀ " # de

结果应为:“特殊字符空间88323kek郭"

我已经试过了
print'。使用和函数连接(c代表字符串中的c。如果u'\u4e00'解决方案,则解码('utf-8'):

string = "Special $#! characters   spaces 888323 Kek  ཌི ༜ 郭 ༜  དྀ    "
输出:

import re

string = "Special $#! characters   spaces 888323 Kek  ཌི ༜ 郭 ༜  དྀ    "

# defining the pattern which should match all characters excepting alphanumeric and chinese
pattern = re.compile(u'[^a-z0-9⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE | re.IGNORECASE)
result = pattern.sub('', string)

# print(result)  Python v.3 printing
print result

我不想删除像“$!?”@RomanPerekhrestexception special chac like!@$%^&*():“/。@ChinYe,根据您的“异常列表”'special$\!CharactersPaces88323k显示预期结果如何郭' 像这样,只需将这些字符添加到pattern character类中,它将适用于您的新案例:
pattern=re.compile(u'[^a-z0-9!@$%^&*():“/。⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE | re.IGNORECASE)
Specialcharactersspaces888323Kek郭