I am looking for removing foo
parameter and its value from all the possible following query strings in Java.
Is there a regex pattern to do this?
http://localhost/test?foo=abc&foobar=def
http://localhost/test?foobar=def&foo=abc
http://localhost/test?foo=abc
http://localhost/test?foobar=def&foo=abc&foobar2=def
The resulting strings would be
http://localhost/test?foobar=def
http://localhost/test?foobar=def
http://localhost/test
http://localhost/test?foobar=def&foobar2=def
This regex should match the GET param and its value...
(?<=[?&;])foo=.*?($|[&;])
RegExr.
Just replace it with an empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With