V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
fangwenxue
V2EX  ›  正则表达式

求个正则

  •  
  •   fangwenxue · 2021-11-21 17:41:40 +08:00 · 584 次点击
    这是一个创建于 858 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想要的结果 求个正则
    const s = '/hello'  // match[1] = hello
    const s = '/hello/abcd' // match[1] = hello // match[2] = /abcd
    const s = '/hello/' // match[1] = hello // match[2] = /
    
    console.log(s.match(/\/([^\/]+)?(.+)/i))
    
    1 条回复    2021-11-21 21:56:00 +08:00
    jackmod
        1
    jackmod  
       2021-11-21 21:56:00 +08:00
    ^/([^/]*)(.*)$
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3001 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.