Replace non alphanumeric characters except some exceptions python

后端 未结 3 1378
暖寄归人
暖寄归人 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:39

    I believe the approach you describe in perl could also be used in python, eg:

    re.sub(r'[^\w=]', '',mystring)
    

    would remove everything except word-characters and =

提交回复
热议问题