i have a link that is
dashboard/permissions?page=2
so in javascript i want check if this link's last has "?page=2" or not
if has then remove it
Note: here ?page=2 2 is changeable
so how to do it in javascript
i have a link that is
dashboard/permissions?page=2
so in javascript i want check if this link's last has "?page=2" or not
if has then remove it
Note: here ?page=2 2 is changeable
so how to do it in javascript
var testStr = document.URL;
console.log(testStr.match(/\?page=\d+/) !== null);
Try the following regex: \?page=\d+
:
var url = 'dashboard/permissions?page=2';
alert(url.match(/\?page=\d+/));
And to remove it :
if(url.match(/\?page=\d+/)!==null) {
url=url.replace(/\?page=\d+/, "");
alert(url);
}
//returns "dashboard/permissions"