3

I need to remove the jsessionid from the given URL .The jessionid is not in the query part for example i have URL like

http://example.com/index.do;jsessionid=XXXXXXXXXXXXXXX?username=example
Ramesh
  • 2,217
  • 5
  • 33
  • 62

1 Answers1

9

Try this:

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

This will work whether or not your url has any parameters, eg, it will work for both of these:

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

It employs a regex "look ahead" to capture up to (but not including) either a ? or end of input.

Bohemian
  • 389,931
  • 88
  • 552
  • 692