正则表达式不适用于Google Analytics,可能是由于积极向前? [英] Regular Expression not working in Google Analytics, possibly due to Positive Lookahead?

查看:102
本文介绍了正则表达式不适用于Google Analytics,可能是由于积极向前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个正则表达式,可以在Regex101中完美工作(查看演示)。 anubhava $ b

  / ^(?=。* ?\b [1-9] \b)(= * \b1 [0-7] \b)[0-9] +(:,[0-9] +)+ $ /克

但是,当我尝试在Google Analytics中使用它时,出现此警告 - 无效的正则表达式。您的数据请求包含无效的正则表达式。



您知道我如何获得相同的结果,但满足Google Analytics安全要求,这似乎是不容忽视?

解决方案

 ((^ |,)([ 0-9] |(1 [0-7])))*((((^ |)[0-9]([0-9] |(1 [0-7]))*(1 [0-7])))|(((^ |)1 [0-7](([0-9] |(1 [0-7])))*(,[0-9]) )))(,([0-9] |(1 [0-7])))* 

感谢 GA的极其有限的正则表达式语言,这是一个非常低效的总体正则表达式,但它与您的用例相匹配。

https://regex101.com/r/oN2jB0/8


I have a regular expression here which works perfectly in Regex101 (see demo). anubhava provided this solution in this question.

/^(?=.*\b[1-9]\b)(?=.*\b1[0-7]\b)[0-9]+(?:,[0-9]+)+$/gm

However, when I try to use it in Google Analytics, I get this warning - "Invalid regular expression. Your data request includes an invalid regular expression."

Do you know how I can get the same results, but satisfy Google Analytics security requirements, which seem to be disallowing lookaheads?

解决方案

((^|,)([0-9]|(1[0-7])))*((((^|,)[0-9](,[0-9]|(1[0-7]))*(,1[0-7])))|(((^|,)1[0-7]((,[0-9]|(1[0-7])))*(,[0-9]))))(,([0-9]|(1[0-7])))*$

Thanks to GA's extremely limited regex language, this is a pretty inefficient and gross regex, but it matches your use cases.

https://regex101.com/r/oN2jB0/8

这篇关于正则表达式不适用于Google Analytics,可能是由于积极向前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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