I'm having trouble writing a regex that removes any of these parameters from a url using javascript:
pricerange=-#
pricerange=#-#
pricerange=#-
This works ok for all except the last one. It doesn't remove pricerange=40-
var postUrl = "http://www.test.com/directory/?cat=203604&pricerange=-10&pricerange=10-20&pricerange=20-30&pricerange=30-40&pricerange=40-"
postUrl = postUrl.replace(/[&\?]\bpricerange\=[0-9]*-[0-9]*\b/g, "");
Result:
http://www.test.com/directory/?cat=203604&pricerange=40-
Expected result:
http://www.test.com/directory/?cat=203604
Here is the jsbin.
There could be other parameters in the url that I wouldn't want to remove.