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'
Answer from arshajii on Stack Overflow
Top answer
1 of 3
1

Your method seems ok, but if you want to use a regex (like the tag suggests) you can use this to capture all the characters that are not lower/uppercase letters or spaces:

[^a-zA-Z ]*

Then you can replace with an empty string.

import re

input_text = "This is a test number +223/34 and this a real number 2333."
clean_text=re.sub("[^a-zA-Z ]*", "", input_text)
2 of 3
1

You can simply check if a token is alphanumeric:

clean_text  = " ".join([word for word in input_text.split() if word.isalnum()])

See a Python demo:

input_text = 'This is a test number +223/34 and this a real number 2333.'
print( " ".join([word for word in input_text.split() if word.isalnum()]) )
# => This is a test number and this a real number

If you have specific patterns in mind, you can write specific regex patterns to find the matching strings and delete them with re.sub. For example, if you want to remove standalone numbers that can contain match operators between them, or dots/commas, you can use the following:

import re
input_text = 'This is a test number +223/34 and this a real number 2333. The email is [email protected] and the website is www.test.com.'
print( re.sub(r'[-+]?\b\d+(?:[.,+/*-]\d+)*\b', '', input_text) )

that yields the expected:

This is a test number  and this a real number . The email is [email protected] and the website is www.test.com.

See the Python demo. The regex means

  • [-+]? - an optional + or -
  • \b - a word boundary (the digit cannot be glued to a word)
  • \d+ - one or more digits
  • (?:[.,+/*-]\d+)* - zero or more repetitions of . / , / +, /, *, - and then one or more digits
  • \b - a word boundary (the digit cannot be glued to a word).
🌐
Stack Overflow
stackoverflow.com › questions › 30123947 › removing-words-containing-digits-from-a-given-string
python - Removing words containing digits from a given string - Stack Overflow
May 24, 2017 - Assuming that your regular expression does what you want, you can do this to avoid removing while iterating. import re def checkio(text): text = re.sub('[,\.\?\!]', ' ', text).lower() words = [w for w in text.split() if not re.search(r'\d', w)] print words ## prints [] in this case
Find elsewhere
🌐
Built In
builtin.com › software-engineering-perspectives › python-remove-character-from-string
How to Remove Characters From a String in Python | Built In
filter() will return an iterator containing all of the numbers in the string, and join() will join all of the elements in the iterator with an empty string. Ultimately, Python strings are immutable, so all of the mentioned methods will remove characters from the string and return a new string.
🌐
Linux Hint
linuxhint.com › remove-number-string-python
Linux Hint – Linux Hint
November 22, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
w3resource
w3resource.com › python-exercises › re › python-re-exercise-49.php
Python: Remove words from a string of length between 1 and a given number - w3resource
July 22, 2025 - Python Exercises, Practice and Solution: Write a Python program to remove words from a string of length between 1 and a given number.
🌐
Stack Overflow
stackoverflow.com › questions › 46768268 › check-if-a-word-contains-a-number › 46768422
python - Check if a word contains a number - Stack Overflow
Goal: Any token which contains a digit should be removed. my current code is something like this which doesn't handle the above types: relevant_tokens = [token for token in tokens if not token.isdigit()] ... @WiktorStribiżew that works and I mentioned that approach in the question when I said: "I can loop through the string item". However, it makes my filter statement too complex. I was more looking for a single function. ... Ok, the first thread linked actually contains the right regex solution, re.search(r'\d', inputString).
🌐
Replit
replit.com › home › discover › how to remove numbers from a string in python
How to remove numbers from a string in Python | Replit
April 13, 2026 - Forgetting non-ASCII digits: The standard isdigit() method only identifies the digits 0-9. If your text contains numerals from other writing systems, such as Arabic or Devanagari, isdigit() will fail to detect and remove them.
🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-all-digits-from-a-list-of-strings
Python | Remove all digits from a list of strings - GeeksforGeeks
December 26, 2024 - This kind of application can come in many domains. Let's discuss certain ways to solve this problem. Method #1 : Using replace() + enumerate() + loop This is · 8 min read Python - Remove String from String List
🌐
Stack Overflow
stackoverflow.com › questions › 39489246 › automatically-remove-numbers-and-alphanumeric-words-except-for-those-containing
python 3.x - Automatically remove numbers and alphanumeric words except for those containing "ème" - Stack Overflow
# Split up by space splittext <- unlist(strsplit(text, split = " ")) # Retain words containing no numbers, or that contain 'ème' or punctuation. selecttext <- splittext[!(grepl("\\d", splittext)) | grepl("ème", splittext) | grepl("[[:punct:]]", splittext)] # If a word contains both numbers and punctuation, retain only the punctuation selecttext[grepl("\\d", selecttext) & grepl("[[:punct:]]", selecttext)] <- stringr::str_sub(selecttext[grepl("\\d", selecttext) & grepl("[[:punct:]]", selecttext)], start=-1, end =-1) # Recombine text2 <- paste(selecttext, collapse = " ") > text2 [1] "Le septembre à , Jean voyait les filles pour la 3ème fois."