您的位置:首页 > 编程语言 > Python开发

python 正则过滤四字节字符

2016-05-20 15:10 531 查看
转载:http://blog.csdn.net/shuifa2008/article/details/41780067

项目中有时需要过滤掉四字节以上的字符(表情),比如MySQL数据库5.5.3以下的版本text字段不支持四字节以上字符

于是就需要过滤掉再入库,Python中的方法为:

[python] view
plain copy

try:  

        # python UCS-4 build的处理方式  

        highpoints = re.compile(u'[\U00010000-\U0010ffff]')  

except re.error:  

        # python UCS-2 build的处理方式  

         highpoints = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')  

  

resovle_value = highpoints.sub(u'??', src_string)  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息