这可以不用正则表达式来完成:
>>> string = "Special $#! characters spaces 888323">>> ''.join(e for e in string if e.isalnum())'Specialcharactersspaces888323'
您可以使用
str.isalnum:
S.isalnum() -> boolReturn True if all characters in S are alphanumericand there is at least one character in S, False otherwise.
如果您坚持使用正则表达式,则其他解决方案也可以。但是请注意,如果可以在不使用正则表达式的情况下完成此操作,那么这是最好的解决方法。



