Search code examples
regexgoogle-analyticsgoogle-analytics-filters

Regex in Google Analytics Advanced Custom Filter not working as expected


I'm trying to setup a custom advanced filter in Google analytics to remove a particular query parameter (sys_id) from the URL when another parameter (id=ticket) is set in the URL.

For example, I want this URL:

/sp?id=ticket&table=incident&sys_id=cb7a9061db05c300d70a38ff9d9619f8

to be captured as:

/sp?id=ticket&table=incident

In my custom advanced filter, I have Field A -> Extract A set to Request URI with regex: (.*id\=ticket.*)(&sys_id=(\w|\d){32})($|\&.*)

In the Output To -> Constructor, I have set Request URI to $A1$A3

Result: Google analytics is logging /sp?id=ticket&table=incident8

Why am I getting the last character (the 8 in the above example) at the end of the string and how do I get rid of it to get just the output I want?


Solution

  • The third capturing group (\w|\d){32} in your pattern is a repeated capturing group, and it stores the last captured value in the group memory buffer (the 8 in your test case).

    Since \w already matches digits, you do not even need the alternation group. You may safely replace (\w|\d){32} with \w{32}.