Last active
July 21, 2019 07:06
-
-
Save luisenriquecorona/50de229b83b638ef2fac92d8c0381e54 to your computer and use it in GitHub Desktop.
The Regular Expressions & Flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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