2024-10-01 07:36:46 发布
网友
tweets中有一个符号:“
“
“@BrownieSWP: High is s***????” you like 12 tf
符号不是"。我写这个正则表达式来匹配它:
"
re.sub('(“|”)', '"', tweet)
这个正则表达式在崇高的文本中工作。但它在python中不起作用。你知道吗
对我来说很管用
>>> s = r"“@BrownieSWP: High is s***????” you like 12 tf" >>> m = re.sub(r'[”“]', r'', s) >>> m '@BrownieSWP: High is s***???? you like 12 tf'
复制/粘贴的字符是U+201C“左双引号”。在re.sub()中也有相应的右引号U+201D。可能您尝试粘贴它的环境没有设置为正确处理Unicode,并将其转换为其他编码。(另见How do I see the current encoding of a file in Sublime Text 2?)
re.sub()
始终可以使用Python的转义码来明确地和ASCII兼容地引用Unicode字符;re.sub(u'[\u201c\u201d]', '', tweet)
re.sub(u'[\u201c\u201d]', '', tweet)
对我来说很管用
复制/粘贴的字符是U+201C“左双引号”。在
re.sub()
中也有相应的右引号U+201D。可能您尝试粘贴它的环境没有设置为正确处理Unicode,并将其转换为其他编码。(另见How do I see the current encoding of a file in Sublime Text 2?)始终可以使用Python的转义码来明确地和ASCII兼容地引用Unicode字符;
re.sub(u'[\u201c\u201d]', '', tweet)
相关问题 更多 >
编程相关推荐