"?page=2&pageSize=12&query=hex"
I have the above text I want to remove page and pageSize along with value. After removing the page and pageSize my text should look like given below.
"?query=hex"
 "?page=2&pageSize=12&query=hex"
I have the above text I want to remove page and pageSize along with value. After removing the page and pageSize my text should look like given below.
"?query=hex"
 
    
    You can use URLSearchParams to remove params of the query:
const queryString = "?page=2&pageSize=12&query=hex";
const searchParams = new URLSearchParams(queryString);
searchParams.delete("page");
searchParams.delete("pageSize");
const resultQuery = `?${searchParams.toString()}`;
Reference: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
 
    
    Here's one way of doing it without any third-party library:
const input = "?page=2&pageSize=12&query=hex"
const parts = input
  .replace(/^\?/, "")
  .split("&")
  .filter(p => !/^(page|pageSize)/.test(p))
const output = "?" + parts.join("&")
console.log(output) 
    
    Using regex you can do that as below:
const str =  "?page=2&pageSize=12&query=hex";
console.log(str.replace(/page.*&/g, "")); 
    
    Here, maybe this will help. Simple to implement and understand.
var str = "?page=2&pageSize=12&query=hex";
var finalStr = '?' + str.substring(str.indexOf('query='))
console.log(finalStr) 
    
    