Executing multiple regex replace on string [duplicate]

I’m currently forming a URL to make a request to and it accepts parameters in a specific way. I’m executing three .replace to replace certain encoded characters.

const parameters = new URLSearchParams(rawUrl).toString();
const commaParams = parameters.replace(/%2C/g, ',');
const numberParams = commaParams.replace(/\#/g,'%23');
const finalParams = numberParams.replace(/%23/g, '#');

return finalParams;

Is there a more concise way to do this, maybe in a singular regex?

Leave a Comment