Q:

need help with regex in javascript to replace string pattern

Need help with regex javascript , i tried few but didn't work
i want to replace the the following string which is a url. The values 200, 400  are dynamic in the below string
url=http://www.test.com?debug=true&MAXWIDTH:200+MAXHEIGHT:400
with ,900 , 900 always and the result should be 
after regex i want the url string contains the below value
url=http://www.test.com/?debug=true&MAXWIDTH:900+MAXHEIGHT:900

A:

var replaceMaxWidthAndHeight = function(str, newWidthAndHeight) {
  var i=0;
  return str.replace(/\s*(MAXWIDTH|MAXHEIGHT)\s*:\s*(\d+)\s*/g, function(s, m1) {
    return m1 + ':' + newWidthAndHeight[i++];
  });
};

var s1 = "url=http://www.test.com/?debug=true&MAXWIDTH:200+MAXHEIGHT: 400";
var s2 = replaceMaxWidthAndHeight(s1, [900, 900]);
s2; // => "url=http://www.test.com/?debug=true&MAXWIDTH:900+MAXHEIGHT:900"
s2 = replaceMaxWidthAndHeight(s1, [10, 20]);
s2; // => "url=http://www.test.com/?debug=true&MAXWIDTH:10+MAXHEIGHT:20"

