Tauren2614 2017-11-27 07:48 采纳率: 100%
浏览 1218
已采纳

一个python的re匹配的疑惑

目的是匹配中文,代码是下面这样的:

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)这里,为什么中文匹配失败,‘;’反而成功了

  • 写回答

2条回答 默认 最新

  • xiao_huocai 2017-11-29 10:12
    关注

    re_zh = re.compile(u'([\u4E00-\u9FA5]+)')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?