I'm new to regex and I'm using it in jquery to remove/replace the url but when i triggered an anchortag with href="#"
the url will add a #
and I'm not able to replace it with my current regex fix to replace the url.
http://localhost:3131/Main/MainPage?a=1221#&ab=&ac=
the original link onload is
http://localhost:3131/Main/MainPage?a=1221
but after triggering an anchortag with href="#"
return, it becomes this:
http://localhost:3131/Main/MainPage?a=1221#
and my expected result upon removing the hash(#) in my url is this:
http://localhost:3131/Main/MainPage?a=1221&ab=&ac=
heres my function for replacing the url when closing modal windows in jquery
function updateQueryStringParameter(uri, key, value, key1,value1) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)" + key1 + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2' + key1 + "=" + value1 + '$3' );
}
else {
return uri + separator + key + "=" + value + separator + key1 + "=" + value1;
}
};
Hope someone can help me as i am a beginner on using Regular expression specially in jquery.
Thanks!
uri = uri.replace('#', '');