import re
strs = "how much for the maple syrup? $20.99? That's ricidulous!!!"
strs = re.sub(r'[?|$|.|!]',r'',strs) #for remove particular special char
strs = re.sub(r'[^a-zA-Z0-9 ]',r'',strs) #for remove all characters
strs=''.join(c if c not in map(str,range(0,10)) else '' for c in strs) #for remove numbers
strs = re.sub(' ',' ',strs) #for remove extra spaces
print(strs)
Ans: how much for the maple syrup Thats ricidulous
例如
假设您打算更改所有非字母数字的内容,可以在命令行上执行此操作:
或者在带有
re
模块的Python中:相关问题 更多 >
编程相关推荐