Sample URL:
.com/projects.php?&filterDate=this_week?page=5
The query strings like I've listed above may or may not have the ?page=5 query string in them. I'm looking for a way to grab the URL (done), search the string to determine whether or not it has the ?page=# query string (also done), add it in if it's not there (also done), but if it is there, replace it with a different number (need help with this). The code currently doesn't change the query string (ie page=5 doesn't change to page=6 or anything else for that matter). It doesn't seem like the .replace method's regex is correct (see current_window_location3 variable) below.
//Get the current URL
var current_window_location = window.location.href;
if(current_window_location.match("\\?page=([^&]+)")){
    //Replace this query string 
    var current_window_location3 = current_window_location.replace("\\?page=([^&]+)", new_page_num);
    //Go to this newly replaced location
    window.location = current_window_location3;
}else{
    //Add clicked '?page=#' query string to the URL
    var current_window_location2 = current_window_location + "?page="+new_page_num;
    //Go to this new location
    window.location = current_window_location2;
}
 
    