Created
February 8, 2020 18:36
-
-
Save jthodge/3e2738e8f037c1ee226fe0381fdd4bd1 to your computer and use it in GitHub Desktop.
This file contains 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
let re = /a/g | |
re.test('ab') // returns true | |
re.test('ab') // this will fail! re.lastIndex === 1 so it starts searching at 'b' | |
re.test('ab') // this will pass! since it failed, re.lastIndex is reset to 0 | |
// https://stackoverflow.com/questions/11477415/why-does-javascripts-regex-exec-not-always-return-the-same-value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment