Alex. – 09-19 Dec 29

AAlex.12/29/2022
I need to replace the url using regex,
current url : http://localhost:3000/#/test/id/123456&gid=1&pid=1
needed url : http://localhost:3000/#/Portfolio/id/123456
code that I tried :
const reg = /&gid=.*&pid=.*/g
            const str = "http://localhost:3000/#/test/id/123456&gid=1&pid=1"
            const newStr = str.replace(reg, "")
            console.log(newStr)

problem is if the url changes to : http://localhost:3000/#/test/id/123456&gid=1&pid=1/test or http://localhost:3000/#/test/id/123456&gid=1&pid=1&test=1 my code will delete everything after &gid... which I don't want, I only need to get rid of gid and pid, is there anyway I can do it?
AAlex.12/29/2022
I meant if the url changes to http://localhost:3000/#/test/id/123456&gid=1&pid=1&test=1/test
I want my code to replace it to http://localhost:3000/#/test/id/123456&test=1/test
but what my code does is it replace it to : http://localhost:3000/#/test/id/123456 which is not good
UUUnknown User12/29/2022
2 Messages Not Public
Sign In & Join Server To View
AAlex.12/29/2022
yes thank's a lot it worked
const reg = /&gid=[0-9]&pid=[0-9]/g
const str =
                "http://localhost:3000/#/test/id/123456&gid=1&pid=1&test=1/test"
const newStr = str.replace(reg, "")
console.log(newStr)
UUUnknown User12/29/2022
3 Messages Not Public
Sign In & Join Server To View