Looking to remove a specific URL parameter from a given URL.
For instance, if the URL is:
http://example.com?foo=bar&baz=boo
And I want to eliminate foo=bar
to get:
http://example.com?baz=boo
Or removing baz=boo
would leave me with:
http://example.com?foo=bar
Attempting to achieve this using regular expressions and the string's replace
function.
This is my approach so far:
// s is "foo"
new RegExp("([&?]+)" + s + "=.*&")
This does not work for cases like:
http://example.com?foo=bar
The issue lies in not matching the &
, struggling to adapt the regex for both scenarios.