Regex matches a 2-level URL, not a 3-level URL (Google Analytics)
I am trying to create content groups in Google Analytics. How to combine a page with sports / [SOMETHING], not sports / [SOMETHING] / [SOMETHING]
Match:
- / sports / football
- / sport / men-basketball
- / sports / baseball
Don't match:
- / sport / men's-basketball / standings
- / sport / football / standings
- / sports / football / scores
source to share
We can say "not following characters" by using [^...]
^
means "not". Therefore, to limit the levels, we can use [^/]
.
Here are some examples:
Match / sport / something: ^/sport/[^/]+$
One must start with / and then exactly 1 / must be followed: ^/[^/]+/[^/]+$
or^(/[^/]+){2}$
Generalized to start with / and follow 4 / no more: ^(/[^/]+){1,5}$
source to share