Created
October 8, 2011 15:07
-
-
Save 3rd-Eden/1272402 to your computer and use it in GitHub Desktop.
Regular expression bug in V8 and Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Removing the
g
flag from the regexp make it work.. WTF :))