Google Analytics Regex - Alternative to no negative lookahead
google-analytics, regex
Solution
Google Analytics doesn't seem to support single-line and multiline modes, which makes sense to me. URLs can't contain newlines, so it doesn't matter if the dot doesn't match them and there's never any need for `^` and `$` to match anywhere but the beginning and end of the whole string.
That means the `(?!.)` in your regex is exactly equivalent to `$`, which matches only at the very end of the string (like `\z`, in flavors that support it). Since that's the only lookahead in your regex, you should never have have had this problem; you should have been using `$` all along.
However, your regex has other problems, mostly owing to over-reliance on `(.*)`. For example, it matches these strings:
test.com/?^#(%)!*%supercalifragilisticexpialidocious
test.com/index_ecky-ecky-ecky-ecky-PTANG!-vroop-boing_rowr.php (ni! shh!)
...which I'm pretty sure you don't want. :P
Try this regex:
test\.com(?:/(?:index_\w+\.php)?(?:\?ref=\d+(?:&e=\d+)?)?)?\s*$
or more readably:
test\.com
(?:
/
(?:index_\w+\.php)?
(?:
\?ref=\d+
(?:
&e=\d+
)?
)?
)?
\s*$
For illustration purposes I'm making a lot of simplifying assumptions about (e.g.) what parameters can be present, what order they'll appear in, and what their values can be. I'm also wondering if it's really necessary to match the domain (`test.com`). I have no experience with Google Analytics, but shouldn't the match start (and be anchored) right after domain? And do you really have to allow for whitespace at the end? It seems to me the regex should be more like this:
^/(?:index_\w+\.php)?(?:\?ref=\d+(?:&e=\d+)?)?$
Problem
Google Analytics does not allow negative lookahead anymore within its filters. This is proving to be very difficult to create a custom report only including the links I would like it to include. The regex that includes negative lookahead that would work if it was enabled is: ``` test.com(\/\??index\_(.*)\.php\??(.*)|\/\?(.*)|\/|)+(\s)*(?!.) ``` This matches: ``` test.com test.com/ test.com/index_fb2.php test.com/index_fb2.php?ref=23 test.com/index_fb2.php?ref=23&e=35 test.com/?ref=23 test.com/?ref=23&e=35 ``` and does not match (as it should): ``` test.com/ambassadors test.com/admin/?signup=true test.com/randomtext/ ``` I am looking to find out how to adapt my regex to still hold the same matches but without the use of negative lookahead. Thank you!