正则表达式匹配 2 级深度 URL 而不是 3 级深度(谷歌分析) [英] Regex to match 2 level deep URL and not 3 level deep (Google Analytics)

查看:34
本文介绍了正则表达式匹配 2 级深度 URL 而不是 3 级深度(谷歌分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Google Analytics(分析)中创建内容组.如何匹配带有运动/[某事]而不是带有运动/[某事]/[某事]的页面

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

匹配:

  • /运动/足球
  • /sport/mens-basketball
  • /运动/棒球

不匹配:

  • /sport/mens-basketball/积分榜
  • /sport/football/积分榜
  • /sport/football/scores

推荐答案

我们可以使用 [^...] 表示不是以下字符",^ 代表为不".所以我们可以使用[^/]来限制级别.

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

这里有一些例子:

匹配/sport/something : ^/sport/[^/]+$

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

必须以/开头,然后正好是 1/必须跟随:^/[^/]+/[^/]+$^(/[^/]+){2}$

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

概括为以/开头,后跟最多 4 个/:^(/[^/]+){1,5}$

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

这篇关于正则表达式匹配 2 级深度 URL 而不是 3 级深度(谷歌分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆