Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Last active July 21, 2019 07:06
Show Gist options
  • Save luisenriquecorona/50de229b83b638ef2fac92d8c0381e54 to your computer and use it in GitHub Desktop.
Save luisenriquecorona/50de229b83b638ef2fac92d8c0381e54 to your computer and use it in GitHub Desktop.
The Regular Expressions & Flag
let text = "hello1 hello2 hello3",
pattern = /hello\d\s?/,
result = pattern.exec(text),
globalPattern = /hello\d\s?/g,
globalResult = globalPattern.exec(text),
stickyPattern = /hello\d\s?/y,
stickyResult = stickyPattern.exec(text);
console.log(result[0]);
console.log(globalResult[0]);
console.log(stickyResult[0]);
pattern.lastIndex = 1;
globalPattern.lastIndex = 1;
stickyPattern.lastIndex = 1;
result = pattern.exec(text);
globalResult = globalPattern.exec(text);
stickyResult = stickyPattern.exec(text);
console.log(result[0]);
console.log(globalResult[0]);
console.log(stickyResult[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment