python去掉文章标点和空格

参考了很多的办法都没有成功,,最后自己一点点试了出来。。。。

import re
temp = "想做/ 兼_职/学生_/ 的 、加,我Q:  1 5.  8 0. !!??  8 6 。0.  2。 3有,惊,喜,哦"
#temp = temp.decode("utf8")
temp = temp.encode('utf-8').decode('utf-8')
string = re.sub("[\u0060|\u0021-\u002c|\u002e-\u002f|\u003a-\u003f|\u2200-\u22ff|\uFB00-\uFFFD|\u2E80-\u33FF]", ' ', temp)
#string = re.sub("[\s+\.\!\/_,$%^*(+\"\']+|[+——!,。?、~@#¥%……&*()]+".encode("utf8"), "".encode("utf8"),temp)
string = string.replace(' ','')
print(string)

最后的结果是这样滴

猜你喜欢

转载自blog.csdn.net/h_666666/article/details/85344969