Get-Parameter hinzufügen oder ändern

const addOrUpdateUrlGetParam = function(name, value) {
	let href = window.location.href;
	let regex = new RegExp('[&\\?]' + name + '=');
	if (regex.test(href)) { // the parameter name is already set
		regex = new RegExp('([&\\?])' + name + '=\\d+');
		href = href.replace(regex, '$1' + name + '=' + value);
	} else { // the parameter is not yet set
		if (href.indexOf('?') > -1) { // another parameter is already set
			href = href + '&' + name + '=' + value;
		} else {
			href = href + '?' + name + '=' + value;
		}
	}
	window.history.replaceState(null, null, href);
};