Replace non alphanumeric characters except some exceptions python

后端 未结 3 1389
暖寄归人
暖寄归人 2021-02-14 12:02

In perl s/[^\\w:]//g would replace all non alphanumeric characters EXCEPT :

In python I\'m using re.sub(r\'\\W+\', \'\',mystring)

3条回答
  •  长情又很酷
    2021-02-14 12:47

    re.sub(r'[^a-zA-Z0-9=]', '',mystring)
    

    You can add whatever you want like _ whichever you want to save.

提交回复
热议问题