我有这个字符串:更换一个词出现的所有字符串在python
"Tag: tie, Tag: ball, Tag: honey"
我要替换“标签:”有“”让我有:
tie, ball, honey
我想我应该使用re.sub,但我无法编写适当的正则表达式。
我该如何实现这一结果?
我有这个字符串:更换一个词出现的所有字符串在python
"Tag: tie, Tag: ball, Tag: honey"
我要替换“标签:”有“”让我有:
tie, ball, honey
我想我应该使用re.sub,但我无法编写适当的正则表达式。
我该如何实现这一结果?
很简单:
s = "Tag: tie, Tag: ball, Tag: honey"
print s.replace("Tag: ", "")
使用替换:
s="Tag: tie, Tag: ball, Tag: honey"
print s.replace("Tag:","")
应该是“Tag:”我想。 – vminof 2014-10-10 11:13:52
Tag:\s*
尝试this.Replace通过empty string
。
re.sub(r"Tag:\s*","",x)
这里x是你的输入字符串。
查看演示。
一个简单的字符串替换不起作用? – Jerry 2014-10-10 10:54:19
['str.replace'](https://docs.python.org/2/library/string.html#string.replace) – grc 2014-10-10 10:55:25