Regex to match 2 level deep URL and not 3 level deep (Google Analytics)

前端 未结 2 579
难免孤独
难免孤独 2020-12-18 03:40

I\'m trying to create content groups in Google Analytics. How do I match a page with sport/[SOMETHING] and not sport/[SOMETHING]/[SOMETHING]

Match:

  • /s
相关标签:
2条回答
  • 2020-12-18 04:26

    We can say "not the following characters" using [^...] the ^ stands for "not". So to restrict the levels we can use [^/].

    Here some examples:

    Match /sport/something : ^/sport/[^/]+$

    Has to start with / and then exactly 1 / has to follow: ^/[^/]+/[^/]+$ or ^(/[^/]+){2}$

    Generalized for start with / and followed by 4 / at most: ^(/[^/]+){1,5}$

    0 讨论(0)
  • 2020-12-18 04:32

    This worked for me ^\/sports\/([^\/]+)\/$

    Explanation: ^/sports/ => category to match with / escaped using \

    ([^/]+) => the not / once or more

    /$ => the closing first level page depth / with a $ stop

    0 讨论(0)
提交回复
热议问题