2014-10-10 78 views
-5

我有这个字符串:更换一个词出现的所有字符串在python

"Tag: tie, Tag: ball, Tag: honey" 

我要替换“标签:”有“”让我有:

tie, ball, honey 

我想我应该使用re.sub,但我无法编写适当的正则表达式。

我该如何实现这一结果?

+0

一个简单的字符串替换不起作用? – Jerry 2014-10-10 10:54:19

+0

['str.replace'](https://docs.python.org/2/library/string.html#string.replace) – grc 2014-10-10 10:55:25

回答

2

很简单:

s = "Tag: tie, Tag: ball, Tag: honey" 
print s.replace("Tag: ", "") 
1

使用替换:

s="Tag: tie, Tag: ball, Tag: honey" 
print s.replace("Tag:","") 
+0

应该是“Tag:”我想。 – vminof 2014-10-10 11:13:52

0

试试这个générique解决方案

(?<=:)[^,]+ 

Demo

相关问题