heat
V2EX  ›  问与答

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

  •  
  •   heat · Nov 3, 2016 · 1363 views
    This topic created in 3630 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   ·   Privacy   ·   Solana   ·   5826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:33 · PVG 15:33 · LAX 00:33 · JFK 03:33
    ♥ Do have faith in what you're doing.