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)
项目中有时需要过滤掉四字节以上的字符(表情),比如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)
相关文章推荐
- Python正则表达式与re模块介绍
- python正则表达式去掉数字中的逗号(python正则匹配逗号)
- python正则表达式判断字符串是否是全部小写示例
- Python正则表达式
- Python正则表达式
- python正则表达式
- 坑爹的Python正则量词
- appium自动化测试框架构建
- 分享自编《Python基础教程》无水印文字版
- 为何Python正则里也有split?
- Mac下使用MySQL
- 正确理解Python文件读写模式字w+、a+和r+
- python类继承时构造函数的执行问题
- python的私有变量解析
- python列表里__setslices__方法函数解析a
- 为Python添加默认模块搜索路径
- Node.js可以做什么?
- Node.js的helloworld 程序
- Node.js小Http服务器
- python字典构造函数dict(mapping)解析