Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created July 11, 2018 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerrard00/faabe22efa45bb0c5142d1cd79510d31 to your computer and use it in GitHub Desktop.
Save gerrard00/faabe22efa45bb0c5142d1cd79510d31 to your computer and use it in GitHub Desktop.
JavaScript Generator Function for RegEx Capture Groups
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