python how to remove all letters from string code example
Example 1: python remove non letters from string
def nospecial(text):
import re
text = re.sub("[^a-zA-Z0-9]+", "",text)
return text
Example 2: python remove letters from string
string = "abc123"
# Method 1
''.join(char for char in string if char.isdigit())
#Method 2
import re
re.sub("[^0-9]", "", string)