What is the best way to strip all non alphanumeric characters from a string, using Python?
The solutions presented in the PHP variant of this question will probably
Regular expressions to the rescue:
import re re.sub(r'\W+', '', your_string)
By Python definition '\W == [^a-zA-Z0-9_], which excludes all numbers, letters and _
'\W
[^a-zA-Z0-9_]
numbers
letters
_