Skip to content

Instantly share code, notes, and snippets.

@a1exlism
Last active March 16, 2018 01:53
Show Gist options
  • Save a1exlism/cd1a7b6183c2837001f0b6d0bcce1197 to your computer and use it in GitHub Desktop.
Save a1exlism/cd1a7b6183c2837001f0b6d0bcce1197 to your computer and use it in GitHub Desktop.
The expression will only match from its `lastIndex` position and `ignores` the global (g) flag if set.
let reg = /^foo/y;
let reg2 = new RegExp(reg.source, 'my');
reg.test('foo'); // false
reg.lastIndex = 1;
reg.test('\nfoo'); // false
reg2.test('foo'); // false;
reg2.lastIndex = 1;
reg2.test('\nfoo'); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment