在看到这个之后,我有兴趣通过查找在最短的时间内执行哪些来扩展所提供的答案,所以我通过timeit对两个示例字符串检查了一些建议的答案:string1 = 'Special $#! characters spaces 888323'string2 = 'how much for the maple syrup? $20.99? That s ricidulous!!!'例1'.join(e for e in string if e.isalnum())string1 - 结果:10.7061979771string2 - 结果:7.78372597694例2import rere.sub('[^A-Za-z0-9]+', '', string)string1 - 结果:7.10785102844string2 - 结果:4.12814903259例3import rere.sub('\W+','', string)string1 - 结果:3.11899876595string2 - 结果:2.78014397621以上结果是平均值的最低返回结果的乘积: repeat(3, 2000000)实施例3可以比实施例1快3倍。