Search code examples
javascriptregexreplacejsessionid

Regex to strip jsessionid from URL


I'm using basic query to strip off jsessionid from a URL. It works on all regex validators except for JSFiddle and my application.

Can someone please point out what could be wrong? Thanks in advance!

Here is the string on which the regex needs to be applied:

alert('http://localhost:7001/lccv/custom/file-upload/serializefile;jsessionid=9yvKT9vMNyQn3MmyGNlh54t2VrLw6PQJ1Y8cM1cQ8JMLggfn6hPX!827161999'.replace(';jsessionid=(.*)$', ''));

http://jsfiddle.net/oedw0zcm/


Solution

  • console.log('http://localhost:7001/lccv/custom/file-upload/serializefile;jsessionid=9yvKT9vMNyQn3MmyGNlh54t2VrLw6PQJ1Y8cM1cQ8JMLggfn6hPX!827161999'.replace(/;jsessionid=(.*)$/, ''));
    

    replace your quotes with regex delimiters /

    fiddle