view raw
Ramesh Ramesh - 6 months ago 47
Java Question

Regular expression to remove jsessionid from the URL using java

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


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:


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