Regular expression to remove jsessionid from url using java

I need to remove jsessionid from the given url. jessionid is not in the request part for example, I have a url for example

http://example.com/index.do;jsessionid=XXXXXXXXXXXXXXX?username=example
+3
source share
1 answer

Try the following:

url = url.replaceAll(";jsessionid=[^?]*", "");

This will work regardless of whether your url has any parameters, for example, it will work for both of them:

  • http://example.com/index.do;jsessionid=XXXXXXXXXXXXXXX
  • http://example.com/index.do;jsessionid=XXXXXXXXXXXXXXX?username=example

It uses the look-ahead regex to capture (but not including) either ?or the end of an input.

+8
source

All Articles