Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created October 8, 2011 15:07
Show Gist options
  • Save 3rd-Eden/1272402 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/1272402 to your computer and use it in GitHub Desktop.
Regular expression bug in V8 and Node.js
var regexp = /\+((?:\+)?[\w\-]+)*(?:\.v\d+\.\d+\.\d+)?(?:\.js)$/g;
console.log(regexp.exec('/socket.io+websocket.v0.8.10.js')); // ["+websocket.v0.8.10.js", "websocket"]
console.log(regexp.exec('/socket.io+websocket.v0.8.10.js')); // null
@3rd-Eden
Copy link
Author

3rd-Eden commented Oct 8, 2011

Removing the g flag from the regexp make it work.. WTF :))

@granthusbands
Copy link

That's the documented behaviour of regexp.exec (and it's used that way by many). With a g flag, you're explicitly asking for exec calls to return each match in turn until there aren't any more and then return null. See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp/exec#Finding_successive_matches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment