我只想删除美元符号“$”。这看起来很简单,但我真的不知道为什么我的代码不起作用。
import re
input = '$5'
if '$' in input:
input = re.sub(re.compile('$'), '', input)
print input
输入仍然是“$5”而不是“5”!谁能帮忙?
最佳答案
尝试使用 replace
代替:
input = input.replace('$', '')
正如 Madbreaks 所说,$
表示匹配正则表达式中的行尾。
这是正则表达式的便捷链接:http://docs.python.org/2/library/re.html
关于 python :如何删除 '$' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15214161/