Python remove anything that is not a letter or number

后端 未结 7 1287
甜味超标
甜味超标 2020-12-24 01:40

I\'m having a little trouble with Python regular expressions.

What is a good way to remove all characters in a string that are not letters or numbers?

Thanks

7条回答
  •  梦毁少年i
    2020-12-24 02:02

    Also you can try to use isalpha and isnumeric methods the following way:

    text = 'base, sample test;'
    getVals = lambda x: (c for c in text if c.isalpha() or c.isnumeric())
    map(lambda word: ' '.join(getVals(word)): text.split(' '))
    

提交回复
热议问题