gpt4 book ai didi

regex - Google Analytics(分析) View 过滤器模式与根目录不匹配

转载 作者:行者123 更新时间:2023-12-03 16:40:01 24 4
gpt4 key购买 nike

我正在尝试使用以下设置创建 Google Analytics View 过滤器模式:

过滤器类型:自定义
包括过滤器字段:请求 URI

过滤器应包括:

/
/ (token1 token2) <-- edge case that needs to be matched
/subdir1
/subdir1/subsubdir
/subdir2
/subdir2/subsubdir

过滤器不应包括:
/admin
/admin.php
/admin/admin.php

我认为可行的方法是:

根目录模式或子目录模式

为了匹配我成功测试的子目录:
^/(subdir1|subdir2).*$

我不知道如何匹配根目录。

我试过了:
^/$
^\/$
^/?$

最终的模式将类似于

^/$|^/(subdir1|subdir2).*$

如何仅匹配根目录?

最佳答案

尝试正则表达式:^(?:\/(?:(?:subdir1|subdir2))?(?:\/.*)*)?$
Demo

解释:

Non-capturing group (?:\/(?:(?:subdir1|subdir2))?(?:\/.*)*)?
? Quantifier — Matches between zero and one times, --> this will match the root directory
\/ matches the character / literally (case sensitive)
Non-capturing group (?:(?:subdir1|subdir2))?
? Quantifier — Matches between zero and one times
Non-capturing group (?:subdir1|subdir2)
1st Alternative subdir1
2nd Alternative subdir2
Non-capturing group (?:\/.*)* --> this will match the / and characters that follow subdir1 or subdir2
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\/ matches the character / literally (case sensitive)
.* matches any character

关于regex - Google Analytics(分析) View 过滤器模式与根目录不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50897656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com