在Python中删除字符串中的最后斜杠和数字

ana*_*ana 0 python regex string

我有这样的字符串:

文字-23

该文本-9

2011年是持续的将要爽-455

我需要从Python中删除字符串中的最后一个数字(我对正则表达式很糟糕).

谢谢你的帮助!

gho*_*g74 5

假设所有文本都以-number结尾

>>> s="2011-is-going-to-be-cool-455"
>>> s.rsplit("-",1)[0]
'2011-is-going-to-be-cool'
Run Code Online (Sandbox Code Playgroud)

要么

>>> iwant=s.rsplit("-",1)
>>> if iwant[-1].isdigit():
...   print iwant[0]
...
2011-is-going-to-be-cool
Run Code Online (Sandbox Code Playgroud)