Strip special characters and punctuation from a unicode string

后端 未结 3 684
滥情空心
滥情空心 2021-01-27 13:26

I\'m trying to remove the punctuation from a unicode string, which may contain non-ascii letters. I tried using the regex module:

import regex
text          


        
3条回答
  •  借酒劲吻你
    2021-01-27 14:08

    Try string module

    import string,re
    text = u"<Üäik>"
    out = re.sub('[%s]' % re.escape(string.punctuation), '', text)
    print out
    print type(out)
    

    Prints-

    Üäik
    
    

提交回复
热议问题