Home > Backend Development > Python Tutorial > python splits mixed Chinese and English strings

python splits mixed Chinese and English strings

高洛峰
Release: 2016-10-19 13:48:26
Original
3836 people have browsed it


#coding=utf-8
import re
s = 'hi新手oh'.decode('utf-8') #举个栗子是字符串s,为了匹配下文的unicode形式,所以需要解码
p = re.compile(ur'[\u4e00-\u9fa5]') #这里是精髓,[\u4e00-\u9fa5]是匹配所有中文的正则,因为是unicode形式,所以也要转为ur
   
print p.split(s) #使用re库的split切割
Copy after login

   


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template