【发布时间】:2014-03-22 22:55:40
【问题描述】:
我正在尝试从所有特殊字符中清除字符串并保留其他所有内容,包括标点符号。
mystring = "Q18. On a scale from 0 to 10 where 0 means ‘not at all interested' and 10 means ‘very interested', how interested are you in helping to address problems that affect poor people in poor countries?"
到目前为止我的努力:
newlabel = re.sub('[^A-Za-z0-9]+', ' ', newstring)
输出:
Q18 On a scale from 0 to 10 where 0 means not at all interested and 10 means very interested how interested are you in helping to address problems that affect poor people in poor countries
如何在我目前拥有的正则表达式中保留标点符号或有更好的解决方案?
【问题讨论】:
-
你真的有
very interested'之前的那个unicode字符吗? -
是的。不知道为什么或如何,但它在那里,我想摆脱它:)