Add a space before the \d+.

>>> s = "This must not b3 delet3d, but the number at the end yes 134411"
>>> s = re.sub(" \d+", " ", s)
>>> s
'This must not b3 delet3d, but the number at the end yes '

Edit: After looking at the comments, I decided to form a more complete answer. I think this accounts for all the cases.

s = re.sub("^\d+\s|\s\d+\s|\s\d+$", " ", s)
Answer from oneporter on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-remove-numeric-digits-from-given-string
Python | Ways to remove numeric digits from given string - GeeksforGeeks
December 30, 2024 - import re s = "geeks123" result = re.sub(r'\d+', '', s) # Remove all digits from the string print(result) ... With this approach we iterate through each character in the string and check if it’s an alphabet letter. isalpha() method returns ...
Discussions

python - Removing numbers from string - Stack Overflow
But my guess that you need something very simple so say s is your string and st_res is a string without digits, then here is your code · l = ['0','1','2','3','4','5','6','7','8','9'] st_res="" for ch in s: if ch not in l: st_res+=ch ... I'd love to use regex to accomplish this, but since you ... More on stackoverflow.com
🌐 stackoverflow.com
Python Regex remove numbers and numbers with punctaution - Stack Overflow
Also, all of those | split the entire regex into distinct parts - that is, the first part matches the start of the string but the second one does not. You may want to read up on creating groups with parentheses. ... Where is this string coming from? HTML parsing?.. ... Most of the current suggestions more or less kill every sequence of digits inside the string. Can you be reasonably sure that there never will be digits in the part you want to keep? How about removing ... More on stackoverflow.com
🌐 stackoverflow.com
nltk - Strip Numbers From String in Python - Stack Overflow
Is there an efficient way to strip out numbers from a string in python? Using nltk or base python? Thanks, Ben More on stackoverflow.com
🌐 stackoverflow.com
python - Using regEx to remove digits from string - Stack Overflow
I am trying to remove all digits from a string that are not attached to a word. Examples: "python 3" => "python" "python3" => "python3" "1something" => "1something" "2" => "" "434... More on stackoverflow.com
🌐 stackoverflow.com
🌐
CodeFatherTech
codefather.tech › home › blog › 4 ways to remove numbers from string in python
4 Ways to Remove Numbers From String in Python - CodeFatherTech
December 8, 2024 - A third option is to use the sub() function of Python’s re (Regular expression) module. The examples in this tutorial will show you multiple ways to remove numbers from a string using Python.
🌐
thisPointer
thispointer.com › home › python › python: remove all numbers from string
Python: Remove all numbers from string - thisPointer
April 30, 2023 - In this article we will discuss different ways to remove characters except digits from string in Python. Python’s regex module provides a function sub() i.e. ... It returns a new string. This new string is obtained by replacing all the occurrences of the given pattern in the string by a replacement string repl. If the pattern is not found in the string, then it returns the same string. Let’s use this to delete all numbers or digits from string in python,
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-all-digits-from-a-list-of-strings
Python | Remove all digits from a list of strings - GeeksforGeeks
July 11, 2025 - Regular Expressions efficiently remove digits from strings by matching and replacing them. This uses the re.sub() function to substitute digits (\d) with an empty string.
🌐
OneLinerHub
onelinerhub.com › python-regex › how-to-remove-numbers-from-a-string-using-python-regex
Python Regex: How to remove numbers from a string using Python regex? - OneLinerHub
Using Python regex, numbers can be removed from a string by using the re.sub() function. This function takes two arguments, the pattern to be matched and the replacement string.
🌐
Regex Tester
regextester.com › 112535
Remove numbers - Regex Tester/Debugger
Regular Expression to Remove numbers from text string
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › python › remove numbers from string python
How to Remove Numbers From String in Python | Delft Stack
February 2, 2024 - The below example code demonstrates how to use the re.sub() method to remove numbers from the string:
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string remove numbers
Python String Remove Numbers - Spark By {Examples}
May 21, 2024 - How to remove numbers from the string in Python? You can remove numeric digits/numbers from a given string in Python using many ways, for example, by
🌐
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
🌐
Built In
builtin.com › software-engineering-perspectives › python-remove-character-from-string
How to Remove Characters From a String in Python | Built In
In this article, I’ll explain how to remove different characters from a string in Python. Remove specific characters from the string. Remove all characters except alphabets from a string. Remove all characters except the alphabets and the numbers from a string.
Top answer
1 of 3
5

Why not just use word boundaries?

\b\d+\b

Here is an example:

>>> import re
>>> words = ['python 3', 'python3', '1something', '2', '434', 'python 35', '1 ', ' 232']
>>> for word in words:
...     print("'{}' => '{}'".format(word, re.sub(r'\b\d+\b', '', word)))
...
'python 3' => 'python '
'python3' => 'python3'
'1something' => '1something'
'2' => ''
'434' => ''
'python 35' => 'python '
'1 ' => ' '
' 232' => ' '

Note that this will not remove spaces before and after. I would advise using strip(), but if not you can probably do \b\d+\b\s* (for space after) or something similar.

2 of 3
3

You could just split the words and remove any words that are digits which is a lot easier to read:

new = " ".join([w for w in s.split() if not w.isdigit()])

And also seems faster:

In [27]: p = re.compile(r'\b\d+\b')

In [28]: s =  " ".join(['python 3', 'python3', '1something', '2', '434', 'python
    ...:  35', '1 ', ' 232'])

In [29]: timeit " ".join([w for w in s.split() if not w.isdigit()])

100000 loops, best of 3: 1.54 µs per loop

In [30]: timeit p.sub('', s)

100000 loops, best of 3: 3.34 µs per loop

It also removes the space like your expected output:

In [39]:  re.sub(r'\b\d+\b', '', " 2")
Out[39]: ' '

In [40]:  " ".join([w for w in " 2".split() if not w.isdigit()])
Out[40]: ''

In [41]:  re.sub(r'\b\d+\b', '', s)
Out[41]: 'python  python3 1something   python     '

In [42]:  " ".join([w for w in s.split() if not w.isdigit()])
Out[42]: 'python python3 1something python'

So both approaches are significantly different.

🌐
Medium
medium.com › apollo-data-solutions-blog › python-regex-search-and-replace-with-re-sub-remove-street-number-from-address-4a325556c25a
Python regex search and replace with re.sub — remove street number from address | by Daniel Chvatik | Apollo Data Solutions Blog | Medium
August 19, 2016 - For example ‘284–12 West Street’ should become ‘West Street’. Luckily, Python has excellent regular expression support via the re library. Here’s what we need to do to remove the street numbers from the address: import readdress = re.sub(r'^[\d-]+ ', '', address, 1) This takes the ‘address’ variabe and does a single regular expression replace (the ‘, 1’ parameter) and assigns it back to ‘address’. It finds a digit (\d) or dash (-), one or multiple times (+) at the beginning of the string (^) followed by a space character (‘ ’) and replaces that with an empty string (i.e.
🌐
YouTube
youtube.com › watch
How to Remove/Strip Numbers from a String in Python TUTORIAL (Common Python Interview Question) - YouTube
Python tutorial on how to remove numbers/integers/digits from a string.This is a common python interview question.Solution:'.join([i for i in x if not i.isdi...
Published   August 4, 2019