目的是匹配中文,代码是下面这样的:
re_zh = re.compile('([\u4E00-\u9FA5]+)')
sent = u'这个东西真心很赞;啊哈哈'
for s in re_zh.split(sent):
s = s.strip()
if not s:
print 'not s:' + s
continue
if re_zh.match(s):
print 'match s:' + s
else:
print 'not match s:' + s
输出如下:
not match s:这个东西真心很赞
match s:;
not match s:啊哈哈
我的疑惑是re_zh.match(s)这里,为什么中文匹配失败,‘;’反而成功了