Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to remove jsessionid from the URL using java [closed]

Tags:

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

http://example.com/index.do;jsessionid=XXXXXXXXXXXXXXX?username=example
like image 963
Ramesh Avatar asked Dec 02 '25 05:12

Ramesh


1 Answers

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.

like image 88
Bohemian Avatar answered Dec 03 '25 20:12

Bohemian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!