Created
July 11, 2018 18:12
-
-
Save gerrard00/faabe22efa45bb0c5142d1cd79510d31 to your computer and use it in GitHub Desktop.
JavaScript Generator Function for RegEx Capture Groups
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
function* getMatches(regex, text) { | |
let match; | |
while((match = regex.exec(text)) != null) { | |
yield match.slice(1); | |
} | |
} | |
const assignmentRegEx = /^(.*)\s+=\s+(.*)\.$/gm; | |
for (const match of getMatches(assignmentRegEx, input)) { | |
console.log(match); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment