I'm trying extract expecific values from a URL. The portions to be extracted are part of the parameter and its respective value.
Because the parameter may be present multiple times I would need to grab all instances along with their respective value
&myparameter[123]=1&myparameter[678]=4
Output should be ;123;1,;678;4
I tried the below but I need them as comma separated, not as individual pairs
var regex1 = /&myparameter\[(.*?)\]=/g; var regex2 = /\]=(.*?)\&/g; var input = '&myparameter[123]=1&myparameter[678]=4&otherthings=rtz'; var match; var y = []; do { match = regex1.exec(input); match2 = regex2.exec(input); if (match) { var x = match[1]; var c = match2[1]; var y = ';' + x + ';' + c; console.log(y); } } while (match); How would I join these results or point me to a more effective way of doing so. Thank you.