V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Axurez
V2EX  ›  问与答

Python 无法匹配中文标点符号

  •  
  •   Axurez · 2014-09-14 12:44:20 +08:00 · 8295 次点击
    这是一个创建于 3539 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Python 2.7


    print(re.match(ur"[\u3002]+",u"啊。"))
    居然是 None。难道句号不是 \u3002 么。。
    8 条回复    2014-09-15 21:49:38 +08:00
    ZzFoo
        1
    ZzFoo  
       2014-09-14 13:04:28 +08:00
    用re.search试一下,match是从开头匹配的
    imn1
        2
    imn1  
       2014-09-14 13:10:19 +08:00
    试试FF61
    GBK中的全角标点基本都在ff00-fffe范围内,3000是兼容全角符号,日语中出现比较多
    http://www.unicode.org/charts/PDF/UFF00.pdf
    Bakemono
        3
    Bakemono  
       2014-09-14 13:29:32 +08:00 via iPad   ❤️ 1
    findall可解w
    14
        4
    14  
       2014-09-14 14:32:21 +08:00 via Android
    @Bakemono 难道我一直只会用re.findall反而避免了很多问题。。。
    Axurez
        5
    Axurez  
    OP
       2014-09-15 19:19:53 +08:00
    @Bakemono 那re.split怎么破。。
    Axurez
        6
    Axurez  
    OP
       2014-09-15 21:05:02 +08:00
    @imn1 也没用噶。。。
    imn1
        7
    imn1  
       2014-09-15 21:41:08 +08:00
    @Axurez 把前面的 r 去掉
    imn1
        8
    imn1  
       2014-09-15 21:49:38 +08:00
    >>> print(re.findall(r"[\u3002]+",u"啊。"))
    ['。']
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1957 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:24 · PVG 00:24 · LAX 09:24 · JFK 12:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.