Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java regex pattern to remove a parameter from query string

Tags:

java

regex

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
like image 594
Sandeep Nair Avatar asked Feb 08 '12 10:02

Sandeep Nair


1 Answers

This regex should match the GET param and its value...

(?<=[?&;])foo=.*?($|[&;])

RegExr.

Just replace it with an empty string.

like image 123
alex Avatar answered Oct 20 '22 20:10

alex