我想从一个字符串中删除数字,该字符串正好放在单词后面,没有任何空格。例如:
'Senku Ishigami is charecter from a manga series98 onging since 2017.'
应该:
'Senku Ishigami is charecter from a manga series onging since 2017.'
我可以使用正则表达式删除检测数字'[a-z]+[0-9]+',但是当我无法理解如何删除它时。我试图通过编写来删除它'[a-z]',因为我认为它会起作用,但它只是'[a-z]'作为字符串打印。
这是代码:
import re
text ='Senku Ishigami is charecter from a manga series98 onging since 2017.'
text = re.sub(r'[a-z]+[0-9]+', '[a-z]', text)
print(text)
输出:
Senku Ishigami is charecter from a manga [a-z] onging since 2017.
绝地无双
一只斗牛犬
相关分类