coolair
V2EX  ›  问与答

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

  •  
  •   coolair · Jun 21, 2016 · 5638 views
    This topic created in 3789 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
    cuiqiangtj
    Jun 21, 2016
    1
    [\(((]
    {?=(|\(|(|}
    这样都行吧
    coolair
    coolair
    OP
    Jun 21, 2016
    2
    @cuiqiangtj 不行,是要匹配括号内的东西
    cuiqiangtj
    cuiqiangtj
    Jun 21, 2016❤️1
    3
    @coolair 晕,你把右半边加上不就行了......
    [\(((] (.+)[))\) ]
    klesh
    klesh
    Jun 21, 2016❤️1
    4
    /[(|\(](.*?)[\)| )]/.exec('( abc)')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1719 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:18 · PVG 01:18 · LAX 09:18 · JFK 12:18
    ♥ Do have faith in what you're doing.