Python: Strip everything but spaces and alphanumeric

后端 未结 4 558
时光说笑
时光说笑 2020-12-14 06:37

I have a large string with brackets and commas and such. I want to strip all those characters but keep the spacing. How can I do this. As of now I am using

s         


        
4条回答
  •  一个人的身影
    2020-12-14 06:51

    A bit faster implementation:

    import re
    
    pattern = re.compile('([^\s\w]|_)+')
    strippedList = pattern.sub('', value)
    

提交回复
热议问题