Stripping everything but alphanumeric chars from a string in Python

前端 未结 11 1456
不思量自难忘°
不思量自难忘° 2020-11-22 10:52

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

11条回答
  •  庸人自扰
    2020-11-22 11:27

    for char in my_string:
        if not char.isalnum():
            my_string = my_string.replace(char,"")
    

提交回复
热议问题