从字符串中删除参考号



如何从字符串中删除参考号,例如

text = "It is known that bananas are yellow [1] and tomatoes are red [2]."

输出:

"It is known that bananas are yellow and tomatoes are red."

它是正则表达式还是其他什么?

编辑:我想我对这个问题再准确不过了。谢谢你的回答。

你可以这样做,

In [8]: import re
In [9]: re.sub("([d])", "", text)
Out[9]: 'It is known that bananas are yellow  and tomatoes are red .'

最新更新