Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Created February 6, 2020 16:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianloveswords/0e85c8eca3f73853408f69702ab4b3eb to your computer and use it in GitHub Desktop.
Save brianloveswords/0e85c8eca3f73853408f69702ab4b3eb to your computer and use it in GitHub Desktop.
let re = /a/g
re.test('ab') // 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment