Bootstrap

python正则表达式查找汉字

使用正则表达是查找汉字之前,要将所有的字符串都转码成utf8

import re


string_test = "This is test string 这是测试字符串"
string_test = string_test.decode('utf-8')  # 转码

pattern = ur'[\u4e00-\u9fff]+'  # 汉字正则表达式
re_compile = re.compile(pattern)

res = re_compile.findall(string_test)
print res

 

转载于:https://www.cnblogs.com/buxizhizhoum/p/8603264.html

;