Skip to content

Instantly share code, notes, and snippets.

@jthodge
Created February 8, 2020 18:36
Show Gist options
  • Save jthodge/3e2738e8f037c1ee226fe0381fdd4bd1 to your computer and use it in GitHub Desktop.
Save jthodge/3e2738e8f037c1ee226fe0381fdd4bd1 to your computer and use it in GitHub Desktop.
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