我有这样的正则表达式:
^(.*?(\b\/luxury\/property\b)[^$]*)#contact-broker-msg$
匹配url字符串,如下所示:
https://www.my-website.com/luxury/property/something#contact-broker-msg
但是当我尝试在Google Analitics中应用此正则表达式时,它会输出怀疑结果,就好像它与我网站的网址不匹配一样。
我在这里测试了这个正则表达式:
https://regex101.com/r/Jdd4vK/1
它表明示例字符串是提供的正则表达式的完全匹配。
基本上,我只需要匹配包含\/luxury\/property\
并以#contact-broker-msg
结尾的网址的正则表达式。
那么,关于谁的错误,我或谷歌的任何想法?
答案 0 :(得分:1)
我只需要匹配包含
/luxury/property
并以#contact-broker-msg
结尾的网址的正则表达式。
Google Analytics RE2模式不需要完整的字符串匹配,即也会返回部分匹配。因此,您不必将整个字符串与您的模式匹配。
另一点是,由于未使用正则表达式分隔符,因此您无需在RE2模式中转义/
。
你需要的只是
/luxury/property/.*#contact-broker-msg$
请参阅regex demo。
<强>详情
/luxury/property/
- 文字字符串/luxury/property/
.*
- 除了换行符之外的任何0 +字符#contact-broker-msg
- 文字字符串#contact-broker-msg
$
- 字符串结束。