I've this URL replace query:
window.history.pushState(null, null, window.location.search.replace(/\bcolor=[^&]*/, '$&,Red'));
It works like it should but how can I change the first thing and replace color
by a variable do make this dynamically like this way:
var value = 'color';
window.history.pushState(null, null, window.location.search.replace(/\b var_in_here =[^&]*/, '$&,' + filter_value.attr('data-value') + ''));
Update
Because of the first answer from Jonas I've tried this here but it don't works:
var re = new RegExp('\b' + name + '=[^&]*');
window.history.pushState(null, null, window.location.search.replace(re, '$&,' + filter_value.attr('data-value') + ''));