Reputation: 544
I am trying to track certain metrics in google analytics, but I only want to grab the params, remove sensitive information and send them off as a comma separated string. Such that:
this=me&that=you
would be fired off to ga as:
this,that
I have tried using Angular's native URL parser but I think I may need something more complex and I am not versed enough in REGEX to yank these out simply. Any help is greatly appreciated.
Upvotes: 3
Views: 155
Reputation: 626826
You can replace all =
+ values with commas, and then right-trim the final comma (if any) with regexps and replace
in JS like this:
var str = "this=me&that=you";
var result = str.replace(/=[^&]+(?:&|$)/g, ',').replace(/,$/,'');
document.getElementById("r").innerHTML = result;
<div id="r"/>
Upvotes: 1