Removing non numeric characters from a string

The easiest way is with a regexp

import re
a="lkdfhisoe78347834 (())&/&745  "
result = re.sub('[^0-9]','', a)

print result
>>> '78347834745'

Leave a Comment