I'm having a problem with replacing unnecessary character sets from a string. The following regex replaces the first occurrence of the character set "&=&" but doesn't take care of the leftovers. How does one replace the first and any consecutive occurences of a character set with regex?
var test = "var1=data1&var2=data2&=&=&=&=&var3=data3&=&=&var4=data4&var5=&var6=data6";
var result = "";
result = test.replace(/(\&\=\&)+/g, '&');
// Result returns "var1=data1&var2=data2&=&=&var3=data3&=&var4=data4&var5=&var6=data6"