I have a requirement of removing a query parameter coming with a REST API call. Below are the sample URLs which need to be considered. In each of this URL, we need to remove 'key' parameter and its value.
- /test/v1?key=keyval¶m1=value1¶m2=value2
- /test/v1?key=keyval
- /test/v1?param1=value1&key=keyval
- /test/v1?param1=value1&key=keyval¶m2=value2
After removing the key parameter, the final URLs should be as follows.
- /test/v1?param1=value1¶m2=value2
- /test/v1?
- /test/v1?param1=value1
- /test/v1?param1=value1=¶m2=value2
We used below regex expression to match and replace this query string in php. (https://regex101.com/r/pK0dX3/1)
(?<=[?&;])key=.*?($|[&;])
We couldn't use the same regex in java script. Once we use it in java script it gives some syntax errors. Can you please help us to figure out the issue with the same regex ? How can we change this regex to match and remove query parameter as mentioned above?