初学Python,有个关于正则表达式的问题有疑惑。

按照以上写法,理解打印的是把汉字替换为空格后的内容,但实际却是反过来的,即打印的是把非汉字替换为空格后的内容。
还请熟悉的童鞋解答下!
strs = 'Hello. 先生. What can i do for you? . 你好'
strs = re.sub(r'[\u4e00-\u94a5]', ' ', strs)
print(strs)

第1个回答  2017-04-11

我运行是正确的

本回答被网友采纳
第2个回答  2017-04-11

strs = 'Hello. 先生. What can i do for you? . 你好'
print re.sub(u'[\u4e00-\u9fa5]', '', strs.decode('utf-8'))

相似回答