Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created August 27, 2013 18:26
Show Gist options
  • Select an option

  • Save WebReflection/6357168 to your computer and use it in GitHub Desktop.

Select an option

Save WebReflection/6357168 to your computer and use it in GitHub Desktop.
just a lazy split example based on generators
// @example
// var split = lazySplit(
// 'a.\nb.c',
// /\.(?:[\n\r]*?)?/g
// );
function* lazySplit(str, re) {
for (var
i = 0;
re.test(str);
i = re.lastIndex
)
yield str.slice(
i,
re.lastIndex -
RegExp.lastMatch.length
)
;
yield str.slice(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment