oldstr = """Jamie's car broke "down" in the middle of the street""" #Your problem string
newstr = oldstr.replace('\'', '').replace('"', '')) #New string using replace()
print(newstr) #print result
s = """Jamie's car broke "down" in the middle of the street"""
print(s.replace('\'', '').replace('"', ''))
# Jamies car broke down in the middle of the street
>>> import re
>>> my_str = """Jamie's car broke "down" in the middle of the street"""
>>> re.sub('[^A-Za-z0-9\s]+', '', my_str)
'Jamies car broke down in the middle of the street'
试试这个:
这将返回:
依次使用
replace()
:您可以使用regex从字符串中删除所有特殊字符,如下所示:
相关问题 更多 >
编程相关推荐