heat
V2EX  ›  问与答

一个非捕获正则匹配的问题

  •  
  •   heat · Nov 3, 2016 · 1175 views
    This topic created in 3502 days ago, the information mentioned may be changed or developed.
    http://www.bilibili.com/video/av4542195/
    http://www.bilibili.com/video/av4542195/index_2.html

    想要同时匹配这两个网址,并拿到avid和pageid,为何 #av(\d+)\/(?:index_(\d+)\.html)# 只能匹配到后者呢?
    2 replies    2016-11-03 11:03:02 +08:00
    mcfog
        1
    mcfog  
       Nov 3, 2016   ❤️ 1
    少个问号,不是可选的话当然只能匹配到全有的 case

    试试这个
    av(\d+)\/(?:index_(\d+)\.html)?
    heat
        2
    heat  
    OP
       Nov 3, 2016
    @mcfog 蒙逼了,非常感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2732 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 15:18 · PVG 23:18 · LAX 08:18 · JFK 11:18
    ♥ Do have faith in what you're doing.