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

Python 无法匹配中文标点符号

  •  
  •   Axurez · 2014 年 9 月 14 日 · 8634 次点击
    这是一个创建于 4143 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Python 2.7


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