V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
coolair
V2EX  ›  问与答

正则表达式匹配括号怎么写?

  •  
  •   coolair · Jun 21, 2016 · 5269 views
    This topic created in 3602 days ago, the information mentioned may be changed or developed.
    匹配英文括号()这样就可以了 reg = r'\((.+)\)'
    但是如果加上中文括号,怎么弄呢?
    ()
    ()
    ()
    Supplement 1  ·  Jun 21, 2016
    reg = u'[\((](.*?)[\))]'
    搞定
    4 replies    2016-06-21 12:03:17 +08:00
    cuiqiangtj
        1
    cuiqiangtj  
       Jun 21, 2016
    [\(((]
    {?=(|\(|(|}
    这样都行吧
    coolair
        2
    coolair  
    OP
       Jun 21, 2016
    @cuiqiangtj 不行,是要匹配括号内的东西
    cuiqiangtj
        3
    cuiqiangtj  
       Jun 21, 2016   ❤️ 1
    @coolair 晕,你把右半边加上不就行了......
    [\(((] (.+)[))\) ]
    klesh
        4
    klesh  
       Jun 21, 2016   ❤️ 1
    /[(|\(](.*?)[\)| )]/.exec('( abc)')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2155 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:27 · PVG 08:27 · LAX 17:27 · JFK 20:27
    ♥ Do have faith in what you're doing.