我是Python新手,所以这看起来很容易。我试图删除所有#,数字,如果相同的字母连续重复两次以上,我需要将其更改为只有两个字母。这个工作完美,但不与ØÆÅ。Python正则表达式与ØÆÅ字母
任何想法如何用ØÆÅ字母做这件事?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import math, re, sys, os, codecs
reload(sys)
sys.setdefaultencoding('utf-8')
text = "ån9d ånd ååååånd d9d flllllløde... :)asd "
# Remove anything other than digits
text = re.sub(r'#', "", text)
text = re.sub(r"\d", "", text)
text = re.sub(r'(\w)\1+', r'\1\1', text)
print "Phone Num : "+ text
结果我现在得到的是:
Phone Num : ånd ånd ååååånd dd flløde... :)asd
我要的是:
Phone Num : ånd ånd åånd dd flløde... :)asd
我们之前报道过,不是吗?使用Unicode,而不是字节字符串。 –
从我[回答你以前的问题](http://stackoverflow.com/questions/16549161/python-re-compile-and-split-with-charcters/16549766#16549766):*在Python 2中,你会使用[unicode字符串示例],请注意字符串*和* [带有re.UNICODE集的正则表达式] *中的前导u前缀。 –
嗨@MartijnPieters,通过查看你的意见,尝试一些事情,我找到了解决办法。 – boje