Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 3
added 635 characters in body
codeape
  • 101.6k
  • 26
  • 180
  • 202

You need to make sure that your strings are unicode strings, not plain strings (plain strings are like byte arrays).

Example:

>>> string = ×ばつØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿÀÁÂÃ'
>>> type(string)
<type 'str'>
# do this instead
>>> string = u'\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff\xc0\xc1\xc2\xc3'
# or use string = string.decode('utf-8')
>>> type(string)
<type 'unicode'>
>>> print string×ばつØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿÀÁÂÃ
>>> rePat = re.compile(u'[^\xc3\x91\xc3\x83\xc3\xaf]',re.UNICODE)
>>> print rePat.sub("", string)
Ã
codeape
  • 101.6k
  • 26
  • 180
  • 202

AltStyle によって変換されたページ (->オリジナル) /