Python regex to remove all words which contains number
python, regex
Solution
Do you need a regex? You can do something like
>>> words = "ABCD abcd AB55 55CD A55D 5555"
>>> ' '.join(s for s in words.split() if not any(c.isdigit() for c in s))
'ABCD abcd'
If you really want to use regex, you can try `\w*\d\w*`:
>>> re.sub(r'\w*\d\w*', '', words).strip()
'ABCD abcd'
Problem
I am trying to make a Python regex which allows me to remove all worlds of a string containing a number. For example: ``` in = "ABCD abcd AB55 55CD A55D 5555" out = "ABCD abcd" ``` The regex for delete number is trivial: ``` print(re.sub(r'[1-9]','','Paris a55a b55 55c 555 aaa')) ``` But I don't know how to delete the entire word and not just the number. Could you help me please?