var url = 'http://mywebsite.com/?&filters[]=price_gte:20';
var path = '&filters[]=price_gte:';
var value = 10;
How do I replace the &filters[]=price_gte:20
part with the new path? (path + value
)
I've tried RegExp()
:
var re = new RegExp(path);
console.log(url.replace(re, ''));
//returns http://mywebsite.com/?&filters[]=price_gte:20
That didn't even work, let alone adding the digit in the regex. Problem is, price_gte
is a variable (and so will price_lte
be, and whatever other ranges there might come), with a variable digit after it.
Information I have:
- url (
http://mywebsite.com?&filters[]=price_gte:20&filters[]=price_lte:100
) - path (
&filters[]=price_gte:
) - new value (
10
)
Desired result:
http://mywebsite.com?&filters[]=price_gte:10&filters[]=price_lte:100
What am I missing?