python – 删除特定单词后面的所有单词

我想删除特定单词“.c:”之后的所有单词,数字,十六进制数字.

我的界限就像那样 –

line = "Bags has a price.c:123
line = "Bags has a price.c:543ea

我试过以下内容:

d = re.sub(r'[.c:\W+]', '', c)

但它没有给出正确的答案,输出将如下:

output: Bags has a price

最佳答案

>>> line = "Bags has a price.c:123"
>>> line.split(':')[0]
'Bags has a price.c'
>>> line.split('.c')[0]
'Bags has a price'
点赞