johnny utah johnny utah - 1 month ago 12
Python Question

removing numbers that immediately precede words

Trying to get rid of the numbers in the below sentence. Can anyone help?
Thanks

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


My attempt:

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


DESIRED OUTPUT:

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

Jan Jan
Answer

You could go for

[-\d,]+

See it working on regex101.com.

Which in Python would be:

import re

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

Note that you have another kind of dash in your original question here.