Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active January 1, 2020 08:57
Show Gist options
  • Save rauschma/1e04454f5ee1059ab48011354f292515 to your computer and use it in GitHub Desktop.
Save rauschma/1e04454f5ee1059ab48011354f292515 to your computer and use it in GitHub Desktop.

Summary: .global (/g) and .sticky (/y)

/g /y /yg
.exec() at .lI or later at .lI same as /y
.test() at .lI or later at .lI same as /y
.replace() ignores & resets .lI at .lI /g w/o gaps
.replaceAll() ignores .lI TypeError /g w/o gaps
.search() no effect no effect no effect
.match() Array of group 0 captures like .exec() /g w/o gaps
.matchAll() Iterable of match objects TypeError /g w/o gaps

Legend:

  • .lI means .lastIndex
  • If .lastIndex is mentioned, it is also updated.
  • If .lastIndex is not mentioned, it is not changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment