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=XXXXXXXXXXXXXXXhttp://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.
source
share