let str1 = '&par1=1&par2=RR&par3=234,223&par2=A'; let str2 = '&par1=2&par5=pp'; const merge = (str, table = {}) => str.replace(/[?&]+([^=&]+)=([^&]*)/gi, (t, key) => !table[key] && (table[key] = 1) ? t : ''); alert(merge(str1 + str2));