-1

I tried the following JavaScript in developer console of Chrome:

s = "mysessionId=PsGymRfxWIQG9gjNGgRlKw"
s.match("mysessionId=([^\s\;]+)")

A little surprised by the result:

["mysessionId=P", "P"]

I had expected that the () in regexp will match the entire "PsGymRfxWIQG9gjNGgRlKw", instead, it only matched the first character "P".

When I tried the regexp in perl, it does match the entire sessionId.

Any idea why?

packetie
  • 4,839
  • 8
  • 37
  • 72
  • 1
    The Problem is the escaping `"mysessionId=([^\s\;]+)" ==="mysessionId=([^s;]+)"`. So you would have to write it like: `new RegExp("mysessionId=([^\\s\\;]+)")` – Georg Mavridis Mar 13 '17 at 08:44

1 Answers1

-1

I should have used // instead of "".

s.match(/mysessionId=([^\s\;]+)/)

Had to laugh the moment when I figured it out.

packetie
  • 4,839
  • 8
  • 37
  • 72