python拆分中英文混合字符串 - 按中文拆分,python中英文,#coding=utf-


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

评论关闭