I'm wanting to remove any variable in a string that looks like "utm_whatever=whatever". As far as I can tell, there could anywhere from 0 to 5 of utm_whatever variables in the string, they could be delimited by & or &, and I guess that "whatever" could contain any type of character. So it could potentially look like:
?var1=true&utm_campaign=Cmpn+Name,%20Bad&utm_content=55a8aefe04&utm_medium=social&utm_source=facebook&var2=true
In which case, all I would want is:
?var1=true&var2=true
This is what I wrote:
# Remove utm_whatever
$uri =~ s#utm_\w+=.+(&(amp;)*)*##gi;
# Trim repeating &; maybe not necessary since I included (&(amp;)*)* above
$uri =~ s#&&+#&#;
# Trim trailing ? or &; am I right that I don't have to escape ? in brackets?
$uri =~ s#[?&]$##;
Do you guys see any reason why this would catch something other than utm_whatever, or cause any other problems?
Also, can you suggest a way to not require 3 separate commands?