Removing unwanted characters from a string in Python

前端 未结 9 2043
暖寄归人
暖寄归人 2021-01-18 09:06

I have some strings that I want to delete some unwanted characters from them. For example: Adam\'sApple ----> AdamsApple.(case insensitive) Can someone help

9条回答
  •  甜味超标
    2021-01-18 09:52

    I am probably late for the answer but i think below code would also do ( to an extreme end) it will remove all the unncesary chars:

    a = '; niraj kale 984wywn on 2/2/2017'
    a= re.sub('[^a-zA-Z0-9.?]',' ',a)
    a = a.replace('  ',' ').lstrip().rstrip()
    

    which will give

    'niraj kale 984wywn on 2 2 2017'

提交回复
热议问题