Remove All Non-Numeric Characters from String using Python

re.sub function

import re

text = 'Number: +(123) 726-632'
result = re.sub(r'\D', '', text)

print(result)

Leave a Comment

Cancel reply

Your email address will not be published.