python - 删除紧邻单词之前的数字

标签 python regex

尝试去掉下面句子中的数字。有人可以帮忙吗? 谢谢

x="genes1,2,4,5... activation5–10... modifications11–14... previously15."

我的尝试:

x=re.sub(r'([a-z]),([1-100])', r'\1\2', x)

期望的输出:

 "genes... activation... modifications... previously".

最佳答案

你可以去

[-\d,]+

查看working on regex101.com

Python中是:

import re

x="genes1,2,4,5... activation5–10... modifications11–14... previously15."
x = re.sub(r'[-\d,]+', '', x)
print(x)

请注意,您原来的问题中有另一种破折号

关于python - 删除紧邻单词之前的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40475828/

相关文章:

python - 如何从字典键列表中提取特定项目

python - 缺少准确度数据的分类报告输出

python - 在带有 Connexion 的 Python Flask 应用程序中使用哪个记录器

python 为什么有些模块是在 win 上定义的,而不是在 linux 上定义的

python - python中的模板

正则表达式匹配之间的一切

php - 在 php preg_replace 中允许点

c++ - 在 Windows C++ code::blocks 上 boost 正则表达式

javascript - 正则表达式在查找字母字符时分割数字字符串

Java字符串分割正则表达式返回带有多个分隔符的空字符串