Python 3 正则表达式对中文的匹配
2016-05-16 23:58
471 查看
import re s='中文匹配7.14 3000 '.encode('utf-8') s=s.decode('utf8') m =re.findall(u"[\u4e00-\u9fa5]+",s) print(m)
搜了半天网上的都是Python2的代码,根本不能运行,浪费半天时间,
[\u4e00-\u9fa5]+中文正则表达式
看了出错cannot use a string pattern on a bytes-like object
原来类型str和byte不是同一类型无法匹配
稍微改了一下2次编码整成同一类型,成功匹配。
转码带u的字符
s.decode(
'unicode_escape'
)
相关文章推荐
- pythonchallenge 解谜 Level 1
- 文成小盆友python-num2 数据类型、列表、字典
- python数据分析之numpy初始化(一)
- python 中的map(), reduce(), filter
- python学习-day2
- python处理大数据
- Ubuntu下用pyenv进行python环境隔离
- 基于Python的朴素贝叶斯算法实现
- 动态内容爬虫
- python Image模块学习
- Python3写简单爬虫
- Python-----格式化字符
- leetcode(10),Roman to Integer(python)
- Python 格式化字符串
- Python点滴(五)-pandas进阶
- Windows下Eclipse+PyDev安装Python开发环境
- python中模拟进行ssh命令的执行
- python中模拟进行ssh命令的执行
- python
- python学习笔记4-python文件操作