heat
V2EX  ›  问与答

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

  •  
  •   heat · Nov 3, 2016 · 1416 views
    This topic created in 3654 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
    mcfog
    Nov 3, 2016❤️1
    1
    少个问号,不是可选的话当然只能匹配到全有的 case

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