Axurez
V2EX  ›  问与答

Python 无法匹配中文标点符号

  •  
  •   Axurez · Sep 14, 2014 · 8863 views
    This topic created in 4345 days ago, the information mentioned may be changed or developed.
    Python 2.7


    print(re.match(ur"[\u3002]+",u"啊。"))
    居然是 None。难道句号不是 \u3002 么。。
    8 replies    2014-09-15 21:49:38 +08:00
    ZzFoo
        1
    ZzFoo  
       Sep 14, 2014
    用re.search试一下,match是从开头匹配的
    imn1
        2
    imn1  
       Sep 14, 2014
    试试FF61
    GBK中的全角标点基本都在ff00-fffe范围内,3000是兼容全角符号,日语中出现比较多
    http://www.unicode.org/charts/PDF/UFF00.pdf
    Bakemono
        3
    Bakemono  
       Sep 14, 2014 via iPad   ❤️ 1
    findall可解w
    14
        4
    14  
       Sep 14, 2014 via Android
    @Bakemono 难道我一直只会用re.findall反而避免了很多问题。。。
    Axurez
        5
    Axurez  
    OP
       Sep 15, 2014
    @Bakemono 那re.split怎么破。。
    Axurez
        6
    Axurez  
    OP
       Sep 15, 2014
    @imn1 也没用噶。。。
    imn1
        7
    imn1  
       Sep 15, 2014
    @Axurez 把前面的 r 去掉
    imn1
        8
    imn1  
       Sep 15, 2014
    >>> print(re.findall(r"[\u3002]+",u"啊。"))
    ['。']
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5259 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:58 · PVG 15:58 · LAX 00:58 · JFK 03:58
    ♥ Do have faith in what you're doing.