zzlatan

求个正则? pathname/{id}/sub_pathname

  •  
  •   zzlatan · Apr 25, 2022 · 1667 views
    This topic created in 1659 days ago, the information mentioned may be changed or developed.

    里面 id 是个变量,这种该怎么写正则呢。感谢各位大哥,小白谢过了。

    7 replies  •  2022-04-25 16:06:56 +08:00
    DrakeXiang
    DrakeXiang
    Apr 25, 2022❤️1
    1
    pathname\/([^\/]+)\/sub_pathname
    wenzichel
    wenzichel
    Apr 25, 2022
    2
    变量 id 左右两边的 pathname 和 sub_pathname 是固定的吗?

    要写哪个语言的正则?
    zzlatan
    zzlatan
    OP
    Apr 25, 2022
    3
    @wenzichel js 的呢
    zzlatan
    zzlatan
    OP
    Apr 25, 2022
    4
    @wenzichel 对 是固定的
    8888888888
    8888888888
    Apr 25, 2022
    5
    /pathname/(.*?)/sub_pathname
    8888888888
    8888888888
    Apr 25, 2022
    6
    /pathname\/(.*?)\/sub_pathname/
    autoxbc
    autoxbc
    Apr 25, 2022❤️1
    7
    JS 中与路径有关的正则用构造法来写,不用对路径斜杠符进行转义,可读性更高
    /\/a\/b\/c\/d/ <--> new RegExp('/a/b/c/d')
    代价是要对正则斜杠符转义
    /\d+/ <--> new RegExp('\\d+')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1093 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:01 · PVG 07:01 · LAX 15:01 · JFK 18:01
    ♥ Do have faith in what you're doing.