Regular Expression not working in Google Analytics

2019-07-13 22:47发布

问题:

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?

回答1:

((^|,)([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