代码之家  ›  专栏  ›  技术社区  ›  Santhosh

python正则表达式:如何匹配带有反斜杠和方括号的模式

  •  0
  • Santhosh  · 技术社区  · 5 年前

    在python中使用regex,我想匹配任何

    (\asd\jhsdkjh) or (jashdjh\jakshkj) or (jashdj\asdad .. multipletime) or (\\asklasjd) or (as\\lasjdlkj\\\)
    

    基本上在任何地方 one or more back slashes inside a closed brackets

    如何在python中使用regex匹配东西

    1 回复  |  直到 5 年前
        1
  •  0
  •   Marc    5 年前

    re library . 这里有一个例子

    import re
    text = 'a dog (named henry) is running (really fast\\quick) and jumping (one\\two\\three meters) over a wall'
    re.findall(r'[^(]*\\[^)]*',text)
    
    > ['really fast\\quick', 'one\\two\\three meters']